tags: Java development foundation json
The JSON used before, is a key corresponding to a value, a super simple one-to-one relationship. Now useful JSON that can be nestled in layers, taking a data so cumbersome. In fact, just like the IF else statement, if the IF, IF, IF is set, and write the specification is ok, if the code format is not standardized, then we must also look at it. Therefore, for JSON nesting, just remember the symbol ":", it is the key to the rigidity after the symbol, and the layer is stripped, it will be clear. For example, as follows:

From the outside to the outside, the example is an array, and the array is a string of two JSON formats. This analysis is more clear.
How do you take it out of the value of Name4 in your work? . Initially I wanted to take a string intercepted, I still don't know JSonarray. Now I know, it is quite easy to take it out.
Remove the Name4 value process step: 1, convert the above string to the JSonarray object; 2. Remove the first item of the object, the JSONObject object; Name4 value value2.
The string of the JSON array format can be directly converted to Jsonarray in the format of JSonarray through methods: jsonarray.fromObject (string)
</pre><pre name="code" class="java">JSONArray getJsonArray=JSONArray.fromObject(arrayStr);// Convert the result into the form of a JSonarray object
JSONObject getJsonObj = getJsonArray.getJSONObject(0);/ / Get the first item in the JSON array
String result=getJsonObj.getJSONObject("name1").getJSONObject("name2").getJSONObject("name4");
Well, we talk about these two objects.
1.JSONObject
The JSON object is a key corresponding to a value, using a large bracket {}, such as: {key: value}
2.JSONArray
JSON array, using parentheses [], only the items inside the array are also the JSON key value pair format
The JSON object is added to the key value pair, and the JSONA object is added to JSONARRAY.
JSONObject Json = new JSONObject();
JSONArray JsonArray = new JSONArray();
Json.put("key", "value");// JSONObject object Add key value pair
JsonArray.add(Json);// Add JSONOBJECT object to the JSON array
3.jsonObject and MAP
Map and json are all key values, and the MAP is different from the MAP, and the MAP is separated. The JSON key value is separated from the colon in the middle. In fact, JSON is a special form of MAP.
Map<String,String> strmap=new JSONObject();
The demand here is that the MAP acquired by the Request object, and you don't have to return JSON format.
Summary: China brackets are arrays, braces are objects.
Student class Test case Console: output...
Example 1: JSON file program: Example two: program: JSON file Example three program: ...
[Image upload failed... (image-6adce8-1522634020763)] What is JSON? JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy for people to read and write. It is also easy to machi...
One: traverse JsonArray Two: traversing JsonObject...
Reference URL: ...
Json-lib is used to complete the transformation of beans, collections, maps, java arrays, XML and JSON between jars, json-lib depends on several other jar packages (I tried all jars with the latest v...
First introduced jar package: JSONObject Usage: you may receive data format: { "id": "123", "courseID": "huangt-test", "title": "Submit Job"...
Recently, the company developed several projects in the background Action are Json format to the front-end data transfer, so to JSONObject, JSONArray simply study a little, ado, want to use JSONObject...