In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Android how to sort according to the class to generate signature strings, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
First, let's take a look at the class we built.
There are only two properties, merid and appid.
And then the SignStr function.
This is what we said in the previous article, "[practical information] Android generates signature strings based on classes" to the method, so I won't go into details here.
Let's run a trace and take a look.
Enter our characters into the program and run the trace
See that there is an extra serialVersionUID=, in the blue flag in the red box above and enter this function to see the following figure. There is an extra attribute in the fields obtained in it.
When we know the reason, we will revise the plan.
We are adding two judgments, serialVersionUID and change, to solve this problem.
Core code
Public class SignHelper {
Public static String Signstr (T t) {
String str = ""
/ / define a list of attribute names
List lstfieldname = new ArrayList ()
/ / get all the attributes in the current class
Field [] fields = t.getClass () .getFields
/ / iterate through all attributes and write attribute names to List
For (Field field: fields) {
/ / the judgment is to write the attribute name defined by ourselves.
If (! field.isSynthetic ()) {
If (! (field.getName () .equals ("change") | | field.getName () .equals ("serialVersionUID")) {
Lstfieldname.add (field.getName ())
}
}
}
/ / sort the ASCII codes of Lst.
Collections.sort (lstfieldname)
/ / We begin to concatenate strings according to the sorted name
For (String fieldname: lstfieldname) {
/ / get attribute value
String fieldvalue = ""
Try {
Fieldvalue = (String) t.getClass () .getField (fieldname) .get (t)
} catch (Exception e) {
E.printStackTrace ()
}
Str = str + fieldname + "=" + fieldvalue + "&"
}
/ / remove the last & symbol of the string
Str = str.substring (0, str.length ()-1)
Return str
}
}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.