Json and json online resolution

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.