JSON data access is much simpler than XML data access. JSON data can be accessed just like JavaScript objects. For example, in the preceding JSON data, to access the name of the first student, you only need to write: StudentsJSON. student [0]. name.
Instance research
Yahoo provides us with an image search Web service with the URL: http://search.yahooapis.com/imagesearchservice/v1/imagesearch. This Web Service supports returning data in JSON format. The Web Service accepts the following parameters:
You only need to dynamically construct the URL and add it to the src attribute of the dynamically created script tag to obtain the JSON data returned by the Web service. The query results are all in the ResultSet. Result [0] array. After a Web page is created, you can directly open the web page and test it in IE, Firefox, and other browsers on the local machine.
Experiment results and Comparison
We can see that the dynamic script tag technology combined with the JSON data exchange format makes cross-origin access to Web services very easy. However, what are the advantages and disadvantages of using JSON data exchange format in Web Services over XML? The following is an analysis from five aspects.
- Typical method for generating JSON metadata objects
- In-depth analysis of problems related to the JSON format
- Detailed instructions on JSON help
- Summarize the typical methods for generating JSON metadata objects.
- How to correctly use JSON cached data
Readability: the readability of JSON and XML is comparable. JSON adopts common syntax data structures, and XML uses standard labels. Scalability: XML is inherently highly scalable, and JSON is not inferior to XML.
Encoding difficulty: XML has a variety of encoding tools, such as Dom4j and JDom. JSON also provides tools provided by json.org, but JSON encoding is much easier than XML, JSON code can be written without tools, but it is not easy to write XML.
Decoding difficulty: the parsing of XML must take into account the parent node of the child node. The JSON parsing difficulty is almost 0. There is nothing to say about XML. Popularity: XML has been widely used in the industry, and JSON has just begun, but it is in the specific field of Ajax.
In the future, XML may need to be stored in JSON. Then Ajax should become Ajaj Asynchronous JavaScript and JSON.