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?
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?
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.
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.
I have been using the json-framework from on google code. It has worked very well for me.
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.
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.
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.