Use JSON to replace XML

Source: Internet
Author: User
In the new project, XML is basically not used except for the configuration files on which some frameworks depend. JSON basically replaces the original XML location in the program. In the past, we did not want to use a private format, so we chose XML. The reason for choosing XML may be that everyone uses it, so we also use it.

XML is a good technique, but in the current situation, XML is abused. SOAP is a typical abuse of XML, the internal representation of the program using XML is also a typical abuse. In one case, the toString of an object is output in XML format, resulting in a large number of log files. During debugging, a large number of <tags> are displayed in the watch window.

In the new project, we carefully considered this situation and found another option, namely JSON. The reason for choosing JSON is very good:
1. The JSON interpretation performance is better than that of XML, Which is concise and compact.
2. better readability than XML. JSON itself is the syntax of JavaScript, and the thinking of programmers, rather than the thinking of document writing.
3. JavaScript native support. The client browser does not need to use an additional interpreter for this purpose. It is particularly suitable for use in the web environment.

When using json in java, pay attention to the following situations:
1. At present, the quality of Open Source JSON-LIB code is not good, it is best to modify a version on this basis, or re-develop a version.
2. Replace {year: 2007, month: 12,...} in the JSON-LIB with the new Date Method
3. In the JSON-LIB, The propertyName of the object carries "" in the output, for example, {"name": "Wen shao"}, where name is double quotation marks are unnecessary, the output should be judged. If you do not need to add "", the network traffic will be reduced.
4. The JSON interpreter should support simple expressions, such as new Date () and new Date (2939234723), which makes the JSON expression more powerful.
5. JSON should be divided into two types, one supports only simple format, similar to open source JSON-LIB, one is implemented through JavaScript interpreter. The latter can get more powerful expression ability when transmitting data in the program, but it will also lead to security problems, which must be used with caution.

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.