开发者

Ajax: Json vs XML

With the exception of needing an XML file, is there a benefit to using XML over JSON? JSON seems like an easier way to handle a return but I have very litt开发者_如何学编程le experience using one or the other


I recommend JSON over XML when doing Ajax. Why? Because a JavaScript engine can easily turn that JSON response into a JavaScript object... allowing you to access/manipulate that data very easily. You just have to use eval() or JSON.parse() or something similar (depending on the browser/javascript library).

JSON is valid JavaScript; so on the whole it meshes much better with Ajax/Javascript/Web than XML does.

JSON also tends to be a bit less verbose, especially in regards to arrays and key/value pairs... something you are likely to be encountering a lot with web services.

With XML people tend to create their own specialized XML vocabulary. So if anyone wanted to use your services, they'd also have to learn your XML vocab. JSON is much more universal in this regard.


XML or JSON When to use these format?

Click here for Link

JSON JSON uses JavaScript syntax for describing data objects, but JSON is still language and platform independent.

JSON is more lighter and efficient than XML

JSON does not provide any display capabilities because it is not a document markup language.

XML

XML’s strength is extensibility and the avoidance of namespace clashes. It holds any data type and can be used to transport full documents with formatting information included. XML is best used when transporting something like a patient chart or text document with markup included.

XML provide display capabilities.

XML structures are based on elements (which can be nested), attributes (which cannot), raw content text, entities, DTDs, and other meta structures.

Finally,

JSON is a better data exchange format. XML is a better document exchange format. Use the right one for the right job.


Here is an interesting article that compares XML to JSON.... namely the lack of namespaces in JSON make XML better, although XML is bloated.

Also see the comments section

http://norman.walsh.name/2010/11/17/deprecatingXML

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜