数据效率-以JSON还是XML返回? [英] Data efficiency - return in JSON or XML?

查看:132
本文介绍了数据效率-以JSON还是XML返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从页面上通过AJAX返回的数据量很大.一次最多可以记录0-20k条记录,每条记录中包含约10 pepe的数据.现在,此刻,数据以结构化XML返回,而javascript处理了它(为了记录,我目前正在使用jQuery).

I have fairly large set of data returned via AJAX from a page. This can be anything up to 0-20k records at once, each with around 10 peices of data inside. Now, at the moment, the data is returned in structured XML and the javascript deals with it (for the record, I'm using jQuery at the moment).

当XML返回时,jQuery遍历所有称为address的节点(使用.find()函数).然后,它分别对数据进行排序,并可能花费任何时间.但是,看起来代码确实没有它可能有效的效率,而且我对处理大型数据并没有真正的经验.我想数据是XML的好处是我们可以轻松地将其集成到其他事物中,例如Web服务等,但是效率会更好,因为我们不想让用户挂在嘴上".因此,我确定其他人以前可能会问过这个问题,但是更有效的是XML还是JSON?

When the XML comes back, the jQuery loops through all the nodes called address (using the .find() function). It then sorts the data respectively and can take any amount of time. However it does appear the code isn't as efficient as maybe it could be, and I don't really have any experience handling largish data. I guess the benefit of the data being XML is we can easily integrate it into other things, eg Web services etc... but efficiency would be much better as we dont want to leave the user "hanging". So I'm sure other people may have asked this before, but what's more efficient - XML or JSON?

还有,哪个更有用,或者它们都是一样的?

Also, which one is more useful, or are they both the same?

很抱歉,这是一个me脚的问题,这是我第一次使用JSON!

Sorry if it's a lame question, this is one of the first times I've used JSON!

推荐答案

JSON是用于序列化对象的符号.这就是它的重点和目的. XML是用于定义标记语言的,但是我不喜欢它,如果人们将事实fact之以鼻,好像它不能用于数据一样.我发现XML非常适合表示多种数据结构.但是,XML相当通用,在规范,符号和工具大小方面都带来一些开销.

JSON is a notation for serializing objects. That's its focus and purpose. XML is for defining markup languages, but I don't like it if people hammer that fact home as if it can't be used for data. I find XML very suitable for representing a multitude of data structures. However, XML is rather general-purpose and that brings some overhead with it in terms of specification, notation and tool size.

首先,确切地找到您所需要的.您是否需要从更一般的意义上传输数据,或者传递对象是否足够?您是否需要诸如名称空间之类的东西?选择一种可以满足您需求的技术,但不能仅此而已.但是请切记未来的扩展.

First of all, find out exactly what you need. Do you need to transfer data in a more general sense, or is passing around objects sufficient? Will you require things like namespaces? Choose a technology that does what you need, but not more than that. But do keep future expansion in mind.

第二,考虑工具. XML在几乎所有语言中都具有强大的支持.有用于内存中表示(DOM),对象绑定(Java中的JAXB),解析(SAX)的方法... JSON是否在目标环境中提供了尽可能多的支持?另一方面,与JavaScript结合使用时,JSON在客户端方面极为方便.

Secondly, consider the tools. XML has great support in almost any language. There's methods for in-memory representation (DOM), object binding (JAXB in Java), parsing (SAX)... Does JSON have as much support in your target environment? On the other hand, JSON is suppremely convenient on the client-side in combination with JavaScript.

我相信无论技术选择如何,您都可以做所需的事情,并且在每种选择中都有优化的余地.但是还有最后一件事要考虑:也许您不必选择.有时,将数据序列化为JSON或XML可能非常简单.作为Java程序员,这是我唯一能想到的例子,但是在JAX-WS中,有一些方法可以通过最少的代码修改从Web服务获取数据,例如XML,JSON甚至其他格式.

I believe you'll be able to do what you need regardless of technology choice, and within each choice there's room for optimization. But there's one final thing to consider: maybe you don't have to choose. Sometimes it can be really simple to allow data to be serialized as JSON or XML. Being a Java programmer, this is the only example I can come up with, but in JAX-WS there are methods for getting data from webservices as XML, JSON or maybe even other formats with minimal code adaptation.

这篇关于数据效率-以JSON还是XML返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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