码迷,mamicode.com
首页 > Web开发 > 详细

json数据相对于xml数据.

时间:2014-11-29 06:44:14      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   ar   color   os   sp   java   

  • 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数据.

标签:des   style   blog   io   ar   color   os   sp   java   

原文地址:http://www.cnblogs.com/listened/p/4129749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!