哪个更快/更容易在iPhone应用程序中使用:XML还是JSON?

时间:2021-12-15 02:58:24

I am starting to create an iPhone application that will interact with a public API.

我开始创建一个与公共API交互的iPhone应用程序。

My question is, which will be faster and/or easier to work with: XML or JSON?

我的问题是,哪个更快和/或更容易使用:XML或JSON?

5 个解决方案

#1


5  

According to Sam Soffes, TouchJSON outperforms XML property lists:

根据Sam Soffes的说法,TouchJSON优于XML属性列表:

When I was preparing for my talk I decided to do some benchmarks to show how much more awesome plists were than JSON. The plist version was about 8 times faster than my JSON Framework version. I was pretty happy with that result. My friend, Jake, said he was using TouchJSON to parse JSON in his apps, so I figured I’d go ahead and benchmark that one too. I was expecting JSON Framework to beat it because the interface to the JSON Framework is a lot simpler than the interface to TouchJSON.

当我准备我的演讲时,我决定做一些基准测试,以显示比JSON更令人敬畏的plist。 plist版本比我的JSON Framework版本快8倍。我很满意这个结果。我的朋友Jake说他正在使用TouchJSON在他的应用程序中解析JSON,所以我想我会继续进行基准测试。我期待JSON Framework能够击败它,因为JSON Framework的接口比TouchJSON的接口要简单得多。

What I found was very surprising. TouchJSON actually beat plists. It was slightly faster in every test I ran. This is awesome because plists have a much larger file size. They are usually about twice as big as JSON files due to all of the extra markup.

我发现的是非常令人惊讶的。 TouchJSON实际上击败了plists。我跑的每次测试都略快一点。这很棒,因为plists的文件大小要大得多。由于所有额外的标记,它们通常是JSON文件的两倍大。

However, that is a single data point.

但是,这是一个单一的数据点。

#2


5  

In terms of built-in APIs, to my knowledge, there's no native support for JSON, so XML would be the only choice if you didn't want to use external libraries.

就内置API而言,据我所知,JSON没有本机支持,因此如果您不想使用外部库,XML将是唯一的选择。

That said, JSON tends to be much easier to work with because it synthesizes directly into Cocoa objects(i.e. NSDictionary, NSArray, NSString, NSNumber), so I would say JSON is much easier to work with if you're willing to use an external library, and you have good server-side support for JSON. I've had good luck with the json-framework library, so my advice is to give that a try.

也就是说,JSON往往更容易使用,因为它直接合成到Cocoa对象(即NSDictionary,NSArray,NSString,NSNumber),所以我想如果你愿意使用外部的话,JSON更容易使用库,您对JSON有良好的服务器端支持。我对json-framework库运气不错,所以我的建议就是尝试一下。

Another bonus of JSON is that it typically(almost always) will produce smaller file transfer sizes over the network because of its formatting. While saving a few kb might be overlooked, it is a major win on a mobile device with limited bandwidth while on a cell network.

JSON的另一个好处是它通常(几乎总是)会因为格式化而在网络上产生较小的文件传输大小。虽然可以忽略节省几kb,但在蜂窝网络上,带宽有限的移动设备是一项重大胜利。

#3


2  

Can't tell with so little information. It depends on the quality and capabilities of the libraries on either end that deal with that data form.

用这么少的信息说不出来。它取决于处理该数据表单的两端库的质量和功能。

But you already know that JSON will be more compact, because it doesn't have to deal with closing tags (variables and open tags seem a wash to me). Fewer bytes on the wire for JSON.

但是你已经知道JSON会更紧凑,因为它不需要处理结束标记(变量和开放标记对我来说似乎是一种冲击)。 JSON的线路上的字节数更少。

#4


2  

JSON is quite a lot terser which saves bandwidth and makes processing more efficient, so i'd choose that.

JSON相当多,可以节省带宽并提高处理效率,所以我会选择它。

#5


1  

I would also use JSON, with TouchJSON (as suggested earlier). The payload is smaller and the parsing is faster in my own tests. Oh, and by the way, don't use NSXMLParser, it's really slow. Use libxml2 or TouchXML instead. Check out this article about a direct experience with JSON on the iPhone:

我也会使用JSON,TouchJSON(如前所述)。有效负载较小,在我自己的测试中解析速度更快。哦,顺便说一句,不要使用NSXMLParser,它真的很慢。请改用libxml2或TouchXML。看看这篇关于在iPhone上使用JSON的直接体验的文章:

Another possible approach is to generate XML or binary Property Lists, and then deserializing that into native objects. Your server-side application might generate the plist format for you using plistlib on Python or plist for Ruby.

另一种可能的方法是生成XML或二进制属性列表,然后将其反序列化为本机对象。您的服务器端应用程序可能会使用Python上的plistlib或Ruby上的plist为您生成plist格式。

#1


5  

According to Sam Soffes, TouchJSON outperforms XML property lists:

根据Sam Soffes的说法,TouchJSON优于XML属性列表:

When I was preparing for my talk I decided to do some benchmarks to show how much more awesome plists were than JSON. The plist version was about 8 times faster than my JSON Framework version. I was pretty happy with that result. My friend, Jake, said he was using TouchJSON to parse JSON in his apps, so I figured I’d go ahead and benchmark that one too. I was expecting JSON Framework to beat it because the interface to the JSON Framework is a lot simpler than the interface to TouchJSON.

当我准备我的演讲时,我决定做一些基准测试,以显示比JSON更令人敬畏的plist。 plist版本比我的JSON Framework版本快8倍。我很满意这个结果。我的朋友Jake说他正在使用TouchJSON在他的应用程序中解析JSON,所以我想我会继续进行基准测试。我期待JSON Framework能够击败它,因为JSON Framework的接口比TouchJSON的接口要简单得多。

What I found was very surprising. TouchJSON actually beat plists. It was slightly faster in every test I ran. This is awesome because plists have a much larger file size. They are usually about twice as big as JSON files due to all of the extra markup.

我发现的是非常令人惊讶的。 TouchJSON实际上击败了plists。我跑的每次测试都略快一点。这很棒,因为plists的文件大小要大得多。由于所有额外的标记,它们通常是JSON文件的两倍大。

However, that is a single data point.

但是,这是一个单一的数据点。

#2


5  

In terms of built-in APIs, to my knowledge, there's no native support for JSON, so XML would be the only choice if you didn't want to use external libraries.

就内置API而言,据我所知,JSON没有本机支持,因此如果您不想使用外部库,XML将是唯一的选择。

That said, JSON tends to be much easier to work with because it synthesizes directly into Cocoa objects(i.e. NSDictionary, NSArray, NSString, NSNumber), so I would say JSON is much easier to work with if you're willing to use an external library, and you have good server-side support for JSON. I've had good luck with the json-framework library, so my advice is to give that a try.

也就是说,JSON往往更容易使用,因为它直接合成到Cocoa对象(即NSDictionary,NSArray,NSString,NSNumber),所以我想如果你愿意使用外部的话,JSON更容易使用库,您对JSON有良好的服务器端支持。我对json-framework库运气不错,所以我的建议就是尝试一下。

Another bonus of JSON is that it typically(almost always) will produce smaller file transfer sizes over the network because of its formatting. While saving a few kb might be overlooked, it is a major win on a mobile device with limited bandwidth while on a cell network.

JSON的另一个好处是它通常(几乎总是)会因为格式化而在网络上产生较小的文件传输大小。虽然可以忽略节省几kb,但在蜂窝网络上,带宽有限的移动设备是一项重大胜利。

#3


2  

Can't tell with so little information. It depends on the quality and capabilities of the libraries on either end that deal with that data form.

用这么少的信息说不出来。它取决于处理该数据表单的两端库的质量和功能。

But you already know that JSON will be more compact, because it doesn't have to deal with closing tags (variables and open tags seem a wash to me). Fewer bytes on the wire for JSON.

但是你已经知道JSON会更紧凑,因为它不需要处理结束标记(变量和开放标记对我来说似乎是一种冲击)。 JSON的线路上的字节数更少。

#4


2  

JSON is quite a lot terser which saves bandwidth and makes processing more efficient, so i'd choose that.

JSON相当多,可以节省带宽并提高处理效率,所以我会选择它。

#5


1  

I would also use JSON, with TouchJSON (as suggested earlier). The payload is smaller and the parsing is faster in my own tests. Oh, and by the way, don't use NSXMLParser, it's really slow. Use libxml2 or TouchXML instead. Check out this article about a direct experience with JSON on the iPhone:

我也会使用JSON,TouchJSON(如前所述)。有效负载较小,在我自己的测试中解析速度更快。哦,顺便说一句,不要使用NSXMLParser,它真的很慢。请改用libxml2或TouchXML。看看这篇关于在iPhone上使用JSON的直接体验的文章:

Another possible approach is to generate XML or binary Property Lists, and then deserializing that into native objects. Your server-side application might generate the plist format for you using plistlib on Python or plist for Ruby.

另一种可能的方法是生成XML或二进制属性列表,然后将其反序列化为本机对象。您的服务器端应用程序可能会使用Python上的plistlib或Ruby上的plist为您生成plist格式。