views:

6919

answers:

6

There are a few JSON libraries/frameworks available for objective-c developers, but I wanted to get the opinion of the resident gurus here on which one is the best, and why.

Any thoughts?

+18  A: 

Touch JSON tends to be the best in terms of speed and unit test coverage. It's also the most widely adopted and actively developed.

wisequark
any benchmarks available which show the better performance?
catlan
I the author of TouchJSON. I have aggressively optimised it for speed _and_ memory usage. Inside the TouchJSON folder is a benchmarking project you can use to check out the speed. I'll get around to publishing benchmarks myself one day.
schwa
just to let anyone know: TouchJSON available in: http://code.google.com/p/touchcode/ :)
balexandre
Works great on regular Cocoa apps as well.
François Beausoleil
+9  A: 

I've had a great experience with http://code.google.com/p/json-framework/ - it was last updated September 20th, so it's not too far behind, and the API is simple and effective.

rpj
+1  A: 

I have been using the json-framework from on google code. It has worked very well for me.

Lee
+4  A: 

I think "best" depends on what features you're interested in. If you are after a JSON parser/generator that strictly follows the JSON protocol, then you could do worse than use json-framework. (Disclaimer: I am its author.)

It also has a features such as protection against deeply nested structures (could break the stack if left to run wild), pretty-printing the JSON output and sorting the dictionary keys. (This is useful if you want/need to make sure the key ordering in the output is the same after adding/removing entries to a dictionary. Good for automated tests, for example.)

There is on-line documentation generated from the source available.

+1  A: 

I've used both SBJson (mentioned above) and YAJL in projects. SBJSON is a lean and easy to use parser, I've found it easy to integrate but it's performance does fall short when compared to YAJL.

The YAJL implementation comes with pretty effective type coercion (integers, floats, bools, etc turn in to NSNumbers), speed and event driven (sax style) parsing model. The event driven parsing has been a big win when dealing with larger data sets.

SBJSON: http://code.google.com/p/json-framework/

YAJL: http://lloyd.github.com/yajl/

ImHuntingWabbits
A: 

I have actually just finished developing a very fast JsonSerializer (benchmarks here) which also supports Mono (The main reason why I wrote it). It doesn't use any Reflection.Emit so there is a good chance it will just run in MonoTouch. If I get the time, I plan to verify that it works in MonoTouch next week.

Basic Example

var customer = new Customer { Name="Joe Bloggs", Age=31 };
var json = JsonSerializer.SerializeToString(customer);
var fromJson = JsonSerializer.DeserializeFromString<Customer>(json); 

In the meantime you can check out these live examples which are hosted on CentOS/Nginx/Mono FastCGI.

EDIT: BTW I have now verified this and it does in-fact work with MonoTouch.

mythz