XML: easy to expand and redundant.
It is represented by <>. As shown in:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="zhuxuekui.data.UserMapper">
<resultMap id="userResultMap" type="User">
<result property="name" column="username"></result>
<result property="email" column="email"></result>
</resultMap>
<select id="selectUser" parameterType="String"
resultMap="userResultMap">
select
*
from user where username = #{username}
</select>
</mapper>
JSON: it is not easy to expand, but has little redundancy and lightweight development.
Reference: http://www.cnblogs.com/mydomain/archive/2010/12/02/1895018.html JSON basics Summary
Http://www.cnblogs.com/mydomain/archive/2010/12/02/1895030.html
An object is an unordered set of 'name/value' pairs. An object starts with "{" (left parenthesis) and ends with "}" (right Parenthesis. Each "name" is followed by a ":" (colon); "," (comma) is used to separate the "name/value" pairs. [7]
An array is an ordered set of values. An array starts with "[" (left square brackets) and ends with "]" (right square brackets. Values are separated by commas.
Value can be a string, number, true, false, null, object, or array enclosed by double quotation marks ). These structures can be nested.
A string is a collection of any number of Unicode characters enclosed by double quotes. It is escaped using a backslash. A character (character) is a separate string (character string ). A string is very similar to a C or Java string.
Although a JSON string is called a string, its full process is called JavaScript Object Notation-JavaScript Object Notation. This string is parsed as an Object in js, And it is syntax-level. Intra-row blocking is required.
{} Is an object with many attributes. [] Indicates an array. There can be two objects, so you can write one.
{} Can also contain [], which indicates multiple objects.
We can think that http is a network protocol, while JSON is a data protocol, which is used for data transmission.
The above is xml, and the following is json:
String, number, object, array, true, false, null
JSON
{"menu": {
"id": "file",
"value": "File:",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}
}
XML
<menu id="file" value="File" >
<popup>
<menuitem value="New" onclick="CreateNewDoc()" />
<menuitem value="Open" onclick="OpenDoc()" />
<menuitem value="Close" onclick="CloseDoc()" />
</popup>
</menu>