views:

910

answers:

9

I'm writing as simple application that comunicate with an external server. The server currently support yaml, xml and json.

  • Which encoding is fastest on IPhone?
  • Which has better support?
  • What libraries do you suggest?
A: 

Well, if you want to use XML, use a plist, since its supported natively on the iphone. JSON is not, but there are some good c libs available. I support JSON and XML in my app.

Same with XML - there's a bunch - just search around.

It also depends what media-types your server supports - btw, REST isn't really a protocol.

Mr-sk
Thanks. Re. REST It is why I said RESTful protocol :)
Piotr Czapla
heh, ok just being nit picky! = ]
Mr-sk
A: 

It really depends on your need and what kind of data you are going to transfer between server and application. If you want to execute queries to select some piece of data you should choose XML because of XQuery language support. JSON is not supported, as I know. I can nothing to say about YAML.

Kirzilla
+2  A: 

I worked on a project that connected Motorola handsets running J2ME with a speech server in the network. We found that total bandwidth was worth optimizing (this was on a 2.5G network in 2004). So I'd suggest you measure how many bytes each serialization format takes and go with the smaller one (which will be JSON or YAML). You might even consider using a binary protocol like Hessian or Google's Protocol Buffers.

We also discovered that minimizing the number of messages decreased latency, so be on the lookout for ways to send data to the iPhone in fewer, larger chunks, use an HTTP cache on your phone, use HTTP entity tags and If-Modified headers, and so on. Since you're using REST, you're well positioned to leverage all these nice features of HTTP.

Of course this can all very easily be premature optimization, so code it up the easiest way possible and measure first.

Jim Ferrans
A: 

I have not seen any YAML libraries (though it does not mean there are none). I know TouchJSON works pretty well, and there is at least one other.

JSON takes less space than an XML or PLIST feed, BUT needs a little more thinking ahead of time to get the structure right.

One nice aspect of pLists is that you get back dates as objects without parsing. If you pass dates in a JSON decide on a format and use the same format everywhere. NSDateFormatter is not thread safe so you have to make an instance per thread, if you want to use a single date formatter to save resources.

Kendall Helmstetter Gelner
+2  A: 

Using json-framework, making your classes interoperate with JSON is ridiculously easy.

Nick Veys
A: 

I have some benchmarks comparing the performance and payload sizes of the different serializers available here:

http://www.servicestack.net/benchmarks/NorthwindDatabaseRowsSerialization.1000000-times.2010-02-06.html

Basically, if you're developing with .NET web services than you are going to be making a compromise on payload size vs performance, unless you go with another serializer.

Marc's protobuf-net shows the smallest and fastest implementation:

  • 6.72x faster and 4.68x times smaller than MS's fastest Xml Serializer; and
  • 10.18x faster and 2.24x smaller than MS's JSON DataContract Serializer;

Although being a binary protocol, it may be harder to debug.

If your developing with MonoTouch (i.e. C#/Mono for the iPhone) and want to use a text-based format, than you may be interested in my Javascript-like type serializer that has been optimized for size and speed, it also shows modest gains over the available XML and JSON options, namely:

  • 3.5x quicker and 2.6x smaller than the XML DataContract serializer; and
  • 5.3x quicker and 1.3x smaller than the JSON DataContract serializer.

Here's a MonoTouch tutorial showing how to call web services from an iPhone: http://www.servicestack.net/monotouch/remote-info/

mythz
A: 

there is support for all three formats in Objective-C. Just google for them. I would suggest writing a serializer that supports all three. Just make your URL resource request end with .xml|.json|.yaml and have the server decided what to serialize to based on that extension. Then you don't actually have to decide you can switch to whatever you want. Making the serializer pluggable is really easy in most server side implementations.

fuzzy lollipop
+1  A: 
vizionary
A: 

I've created an open source application for iPhone OS 3.0 that shows how to use REST & SOAP services in iPhone application, using XML (using 8 different iPhone libraries), SOAP, JSON (using SBJSON and TouchJSON), YAML, Protocol Buffers (Google serialization format) and even CSV from a PHP sample app (included in the project).

http://github.com/akosma/iPhoneWebServicesClient

The project is modular enough to support many other formats and libraries in the future.

The following presentation in SlideShare shows my findings in terms of performance, ease of implementation and payload characteristics:

http://www.slideshare.net/akosma/web-services-3439269

Basically I've found, in my tests, that Binary Plists + REST + JSON and XML + the TBXML library are the "best" options (meaning: ease of implementation + speed of deserialization + lowest payload size).

In the Github project there's a "results" folder, with an Excel sheet summarizing the findings (and with all the raw data, too). You can launch the tests yourself, too, in 3G or wifi, and then have the results mailed to yourself for comparison and study.

Hope it helps!

Adrian Kosmaczewski