Json and json online resolution
Official network media type of json: application/json.
The extension is. json.
Is a data exchange format.
Json Syntax:
Data is represented by key/value pairs
Use braces to save objects. Each name is followed by a ':' colon. Key-value pairs are separated by commas.
Use square brackets to save the array. Use ',' to separate the array.
Comparison between JSON and XML files
Redundancy:
XML is more redundant than JSON, so it is faster to write JSON.
Array usage:
XML does not contain arrays, while JSON contains arrays.
The Java data type from the front-end JSON string to the back-end. The process is actually decoded Based on the Type ing between JSON and Java.
In Java, JSONObject corresponds to java. util. Map, and JSONArray corresponds to java. util. List, which can be accessed using standard Map or List operations.
Convert a JSON string to a JSON object in JS:
(1) var jsonObj = eval ('+ jsonStr + ')')
(2) var jsonObj = JSON. parse (jsonStr );
Convert a JSON object to a JSON string in JS:
(1) var jsonStr = jsonObj. toJSONString ();
(2) var jsonStr = JSON. stringify (jsonObj );
JSON and Ajax
Ajax dataType: The expected data type returned by the server. If it is specified as "json", the returned Json string is converted to a Json object or a Json array.
Java decoding Json:
Export package: net. sf. json. JSONArray and net. sf. json. JSONObject
Decoding:
Convert the request Json string to a JSON object:
JSONObject jsonObj = JSONObject. fromObject (str );
Convert the request Json string to a JSON array object:
JSONArray jsonArr = JSONArray. fromObject (str );
If (jsonArr. size ()> 0 ){
For (int I = 0; I <jsonArr. size (); I ++ ){
// Traverse the jsonarray and convert each object into a json object
JSONObject jsonObj = jsonArr. getJSONObject (I );
}
}
Question:
Send an ajax request without specifying dataType,
If the response type is specified as json in the background, will the callback function that successfully responds receive a json object or a string?
Send an ajax request when the dataType is specified,
If no response type is specified in the background, is the value received by the callback function for successful response a json object or a string?
Required or not?