Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last month.
The community reviewed whether to reopen this question last month and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
JSON 的优点
1
和字符串"1"
,因为数字、字符串(和布尔值)在 JSON 中的表示方式不同。XML 的优点
Draw
Advantages of JSON
1
and the string"1"
as numbers, strings (and Booleans) are represented differently in JSON.Advantages of XML
Draw
XML
JSON
XML
JSON
XML 的优点
多种语言和框架几乎无处不在的支持。很可能已经有一个工具可以帮助您从 XML 响应中提取信息。
如果您选择的话,它可以遵循具体的模式。一旦验证通过,您就可以说它是正确的并开始解析。
命名空间允许您划分 XML。
JSON 的优点
与 XML 相比轻量级。更少的字符 = 更少的时间通过
网管
。如果您需要 Web 应用程序的某些内容,则使用 Javascript 更容易处理。
Advantages of XML
Near ubiquitous support in a wide array of languages and frameworks. More likely than not there's already a tool out there to help your extract information from an XML response.
It can adhere to a concrete schema if so you choose. Once it validates, you can say it's correct and start parsing.
Namespaces allow you to divide the XML.
Advantages of JSON
Lightweight in comparison to XML. Fewer characters = smaller time going through the
internet tubes
.Easier to handle with Javascript if you need something for a web application.
JSON - 更小,可以作为 JavaScript 对象本地加载(速度是一个值)
XML - 仍然是标准,但较旧(更慢,更大,但不仅仅是 JS)
JSON - smaller and can be natively loaded as JavaScript object (speed is a value)
XML - still standard, however older (slower, bigger, but not only JS)
JSON 是一种比 XML 简单得多的格式。 JSON 仅用于将数据描述为对象层次结构,而 XML 还具有许多其他功能。
如果您只需要发送简单的数据,那么 JSON 是一个不错的选择,因为这正是它的用途。
如果您需要一种更强大的方式来描述数据,那么您将需要 XML,因为 JSON 根本不做任何花哨的事情。
JSON is a much simpler format than XML. JSON is intended only for describing data as an object hierarchy, while XML has many other features as well.
If you only need to send plain simple data, then JSON is a good alternative, as that is just what it's intended for.
If you need a more powerful way of describing your data then you would need XML, as JSON simply doesn't do anything fancy.
它们是同样具有表现力的格式。 JSON 不太冗长。 JSON 可以很容易地在 JavaScript(和其他语言)中解析,XML 也可以很容易地被很多东西解析。
我认为最重要的考虑因素是什么将消耗数据 - 如果您已经有一堆 XML 解释代码,请坚持使用。如果您的所有客户都是 Web 开发人员,请使用 JSON。
They're equally expressive formats. JSON is less verbose. JSON can be parsed easily in JavaScript (and other languages), and XML is parsed easily by many things too.
I think the most important consideration is what will be consuming the data - if you already have a bunch of XML-interpreting code, stick with that. If all your clients are web developers, go with JSON.
更简洁 - XML 使用的单词多于必要的
JSON 更快 - 解析 XML 软件缓慢且麻烦。由于解析大型 XML 文件的冗长性和成本,许多 DOM 操作库可能会导致您的应用程序使用大量内存。
JSON 数据模型的结构与数据相匹配:JSON 的数据结构是映射,而 XML 是树。尽管映射(只是键/值对)可能有限制,但这正是我们想要的,因为它更容易解释并且是可预测的。
在代码中:项目在代码中以相同的方式表示。在许多语言中,尤其是动态语言中,您只需“吞入 JSON”即可立即获得域对象。从 JSON 中的对象转换为代码中的对象很容易,因为它们是对齐的。当从 XML 中的对象转换为代码中的对象时,它们并不对齐,并且有很大的解释空间。
JSON 有限制,但这是一件好事:JSON 在可以建模的对象方面受到限制。有些人可能认为 XML 更好,因为可以对更多对象进行建模,并且它不会禁止开发人员。但即使 JSON 禁止开发人员,它也是以积极的方式,使代码更简单、更可预测且易于阅读。 XML 可以格式化为公司想要的任何外观和功能,但这使开发人员难以阅读、理解和转换。在大多数情况下,人们认为 XML 更好,因为开发人员可以做任何事情,但在简化的时代,少即是多,这使得 JSON 成为更好的替代方案。
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.
从表面上看,JSON 在各方面似乎都更优越 - 它灵活、更紧凑,并且在许多情况下更易于使用(特别是在使用 JavaScript 时),但它缺乏一些关键功能,特别是:
模式支持
即甲方指定文档格式的能力,以及乙方检查他们提供的内容是否与该格式匹配的能力。
这在不同系统之间传递数据时至关重要,因为与预期格式的偏差可能意味着数据无法处理(或更糟糕的是,处理不正确)。
命名空间支持
即能够在同一文档中混合多个源读取(或多个源写入)的数据。
一个实际的例子是 SOAP 协议 - 命名空间允许分离SOAP“信封”或“包装器”数据与序列化的应用程序数据一起传递。这允许 Web 框架处理和处理 SOAP 信封,然后将正文/有效负载数据传递到应用程序。
在开发需要快速、紧凑和方便的数据序列化的 Web 应用程序时,JSON 非常有用,但它的灵活性使其不像 XML 那样适合在不同系统之间传输数据或存储将要读取的数据由第 3 方。
也许这些功能最终会出现在 JSON 中,但目前 XML 是 Web 服务和文件格式等内容的主要格式。
On the face of it JSON seems superior in every way - it's flexible, more compact and in many cases easier to use (especially when working with JavaScript), however it lacks some key features, in particular:
Schema support
I.e. the ability for party A to specify the format of a document, and the ability for party B to check that they are supplying something that matches this format.
This is crucial when passing data between separate systems, where a deviation from the expected format might mean that the data cannot be processed (or worse, is processed incorrectly).
Namespace support
I.e. the ability to mix data intended to be read by multiple sources (or written by multiple sources) in the same document.
An example of this in action is the SOAP protocol - namespaces allow for the separation of the SOAP "Envelope", or "Wrapper" data which is passed alongside the serialised application data. This allows web frameworks process and handle the SOAP Envelope and then pass the body / payload data onto the application.
JSON is very useful when developing a web application where fast, compact and convenient serialisation of data is required, however it's flexible nature is the very thing that makes it less suitable than XML for transferring data between separate systems, or storing data that will be read by 3rd parties.
Perhaps in time these sorts of features will appear in JSON, but for now XML is the dominant format for things like web services and file formats.