JSONObject、JSONArray

JSONObject, JSONArray




1. From the outside to the inside, the example is an array, and the array contains two strings in json format.
2. The value of name4 needs to be taken out at work, how would you take it? . At first, I thought about string interception. I didn't know JSONArray at that time. Now that I know it,
it is quite easy to extract it.

The process steps of taking out the value of name4:
1. Convert the above string into a JSONArray object;
2. Take out the first item of the object, a JSONObject object;
3. Take out the value of name1 JSONObject object;
4. Take out the value of name2 JSONObject object;
5. Take out The value of name4 is value2.
The string in json array format in the example can be directly converted to the format of JSONArray by the method: JSONArray.fromObject(String)

JSONArray getJsonArray=JSONArray.fromObject(arrayStr);//Convert the result into the form of JSONArray object
JSONObject getJsonObj = getJsonArray.getJSONObject (0);//Get the first item in the json array
String result=getJsonObj.getJSONObject("name1").getJSONObject("name2").getJSONObject("name4");


JSONObject
json object is a key corresponding to a value , using braces { }, such as: {key:value}


JSONArray
1.json array, use square brackets [ ], but the items in the array are also in json key-value pair format
2.Json object adds key-value pairs, JSONArray adds Json objects


JSONObject and Map
Map map and JSON is all key-value pairs. The difference is that the key-value pairs in map are separated by an equal sign, and the key-value pairs in json are separated by colons.
In fact, json is a special form of map.

Map<String,String> strmap=new JSONObject();


refer to the original text: http://blog.csdn.net/lishuangzhe7047/article/details/28880009

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327006387&siteId=291194637