In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
JSON data in J2ME under the structure and parsing is what, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need to learn, I hope you can harvest.
Here we describe the construction and parsing of JSON data under J2ME, mainly including creating JSON data pairs and parsing JSON key pairs.
Construction and Parsing of JSON Data under J2ME
JSON provides plug-in packages for use in J2ME environments. The download address is www.JSON.org/java/org.JSON.me.zip
This article briefly explains how JSON can be used in a J2ME environment.
1. Create JSON data pairs
1) Create a single key-value pair wrapper: use JSONObject under org.JSON.me
This class provides various put(**,**) functions, which can be called directly.
eg:JSONObjectJSONObject=newJSONObject(); JSONObject.put("name","");
This creates a simple JSON data pair {"name":"drop without stem"}
2) Create array key-value pair encapsulation: use JSONArray under org.JSON.me
Unlike JSONObject, JSONArray provides the function publicJSONArray put (intindex,Vectorvalue)throwsJSONException to create arrays directly.
In fact, if you need to convert the model class to JSON data in j2me, you can generally define your own function in the model class.
publicStringtoJSONString(){}
2. Parse JSON key-value pairs
1)Parse general JSON key-value pairs (the parsed object must start with "{", otherwise an error will be reported)
Firstly, the parsed object is constructed
Suppose that the parsed object is:
Strings={"age":"16","name":"fall without stalk","gender":"male"}; JSONObjectJSONObject=newJSONObject(s);
Once constructed, use JSONObject.get("age") to get 16, the same for all other values.
2)Parse array key-value pairs (parsed object must start with "]", otherwise an error will be reported)
Suppose that the parsed object is:
Strings=[{"age":"16","name":"samyou","gender":"male"}, {"age":"18","name":"ygy","gender":"female"}]; JSONArray =newJSONArray(s);//two sequences intlength=JSONArray.length(); for(inti=0;i { JSONObjectJSONObject=JSONArray.getJSONObject(i); /* Custom Processing Statements.................................................. * Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.