首页 > 代码库 > json数据相对于xml数据.
json数据相对于xml数据.
- JSON is a valid subset of JavaScript, Python, and YAML
- JSON parsing is generally faster than XML parsing.
- JSON is a more compact format, meaning it weighs far less on the wire than the more verbose XML.
- JSON is easier to work with in some languages (such as javascript, python, and php)
- Formatted JSON is generally easier to read than formatted XML.
- JSON specifies how to represent complex datatypes, there is no single best way to represent a data structure in XML.
- JSON is a natural data structure for Javascript -- it is in fact javascript. This makes it an easy and light model for data transfer <> server/services.
- JSON is a nice format to extract XML data into. It‘s much nicer than extracting a big XML document...into a smaller XML document.
- I am going to assuming that you asking about advantages of each format in the context of an ajax response. The biggest advantage for me is that JSON ends up being much, much easier to traverse, identify, and read nodes than XML. XML methods are cumbersome and long to write, while JSON is much more cruft and simple.
- Helpful In the mobile context - it is also often less verbose than XML which helps to reduce bytes transferred.
- More structural information in the document
- Can easily distinguish between the number 1 and the string "1" as numbers, strings (and Booleans) are represented differently in JSON.
- Can easily distinguish between single items and collections of size one (using JSON arrays).
- Easier to represent a null value.
- Easily consumed by JavaScript
Advantages of XML
- Namespaces allow for sharing of standard structures
- Better representation for inheritance
- Standard ways of expressing the structure of the document: XML schema, DTD, etc
- Parsing standards: DOM, SAX, StAX
- Standards for querying: XQuery and XPath
- Standards for transforming a document: XSLT
eg.
to expand on the last point, the JSON object
{ "foo": { "bar": "baz" } }
could be represented in XML as
<foo bar="baz" .>
or
<foo><bar>baz</bar></baz>
or
<object name="foo">< property name="bar">baz</property ></object>
json数据相对于xml数据.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。