有哪些优势和JSON的缺点VS XML为Ajax请求? [英] What are the advantages and disadvantages of json vs xml for ajax requests?

查看:114
本文介绍了有哪些优势和JSON的缺点VS XML为Ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有哪些优势和JSON的缺点VS XML为Ajax请求? 有没有性能上的区别吗?即是浏览器能够处理一种格式的速度比其他?

What are the advantages and disadvantages of json vs xml for ajax requests? Is there a difference in performance? i.e. are browsers able to process one format faster than the other?

推荐答案

总之,JSON(这可以被认为是JavaScript的一个子集),比XML精简了不少。这有几个积极的副作用

In summary, JSON (which can be thought of a subset of JavaScript) is a lot leaner than XML. This has several positive side-effects

  • 在JSON比相应的XML
  • 在JSON是速度更快,也就是简单的语法 - > 更容易解析(更快的解析)
  • JSON is smaller than corresponding XML
  • JSON is faster, i.e. simpler syntax -> easier parsing (faster parsing)

在我原来的回答这个问题,我的JSON的观点是JavaScript的,我认为这是一个近亲。但JSON是一些独立的, JSON.org 确实描述JSON的一个伟大的工作。它也提供了一个兼容性的JavaScript库,增加了支持 JSON.parse JSON.stringify 时,不支持的浏览器

In my original answer to this question, my view of JSON was that of JavaScript, I considered it to be a close relative. But JSON is something independent and JSON.org does a great job of describing JSON. It's also provides a compatibility library for JavaScript that adds support for JSON.parse and JSON.stringify when not supported by browsers.

评估的时间(中间2009年)被用来评估JavaScript中,它也可以评估JSON,即解析JSON,但它被认为是不安全的,因为它没有允许任意JavaScript来代替它执行。

While eval at the time (mid 2009) was used to evaluate JavaScript, it could also evaluate JSON, i.e. parse JSON, but it was considered unsafe, as it did allow arbitrary JavaScript to execute in its stead.

JSON恰好是一个很好的适合浏览器和一个自然的方式来发展的平台,因为它与JavaScript的密切关系。

JSON just happens to be a very good fit for browsers and a natural way to evolve the platform due to its close relationship with JavaScript.

虽然XML可能被认为具有较好的严密性,由于事实,你可以键入它,也正是这些东西,使之慢了很多(这也是在我看来有点冗长)。但如果这是你真正想要的,你应该使用它的东西,XML同样无处不在。

While XML might be considered to have better rigor due to the fact that you can type it, it is also those things that make it a lot slower (it is also a bit verbose in my opinion). But if this is something you really want, you should use it, XML is equally ubiquitous.

我不会进入一个辩论的动态或静态类型的,但我会说这个。这真的很容易添加的东西对无架构数据前,有很多方法可以做到的验证,不管模式或无模式的。

I will not go into a debate over dynamic or statically typed, but I will say this. It's really easy to add stuff on top of schema-free data and there are plenty of ways to do validation, regardless of schema or no schema.

这篇关于有哪些优势和JSON的缺点VS XML为Ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆