XML and JSON — Advantages and Disadvantages?

前端 未结 8 649
遥遥无期
遥遥无期 2020-12-22 22:12

I recently heard about JavaScript Object Notation (JSON), and after looking it up, it seems like it\'s becoming rather popular as an alternative to the Extensible Markup Lan

8条回答
  •  隐瞒了意图╮
    2020-12-22 22:46

    Less verbose- XML uses more words than necessary

    JSON is faster- Parsing XML software is slow and cumbersome. Many of these DOM manipulation libraries can lead to your applications using large amounts of memory due to the verbosity and cost of parsing large XML files.

    JSON data model’s structure matches the data: JSON’s data structure is a map whereas XML is a tree. Although a map (just key/value pairs) can be limiting, that’s what we want, because it is easier to interpret and is predictable.

    In code: Items are represented the same way in code. In many languages, especially dynamic ones, you can just ‘slurp in the JSON’ and you immediately have your domain object. It is easy to go from objects in JSON to the objects in code because they align. When going from objects in XML to objects in code they do not align and there is a lot of room for interpretation.

    JSON is limiting, but that’s a good thing: JSON is limited in terms of what objects can be modeled. Some may think XML is better because more objects can be modeled and it doesn’t prohibit developers. But even though JSON prohibits developers, it is in a positive way, making the code simpler, more predictable, and easy to read. XML can be formatted to look and function any way a company wants, but it makes it difficult for developers to read, understand, and convert. In most cases people believe XML is better because developers can do anything under the sun but in the age of simplifying, less is more, making JSON a better alternative.

提交回复
热议问题