Categories
Development

Objective-C REST and JSON

Bringing in the HarvestThe first REST based code I wrote for the Mac and iOS was my P8 Library for ping.fm. That code is all NSRequest based and I learned a lot while doing it. Since that time I’ve done a couple more projects that consumed REST Services and XML or JASON.

To that end I thought I’d record some of the libraries I’ve run across. Some I’ve used, others are a curiosity.

REST Libraries

ASIHTTP – I’ve used this library a couple of times and I’m using it on a new project. I like it, but the developer that lovingly created it is giving up on it because people gave him too much crap. That’s a real shame, not only that he’s done with it, but that people would harass him so much he gave up on a very handy piece of code.

LRResty – A simple REST/HTTP client. Apparently this library was inspired by a Ruby implementation. I’m fairly certain this is the library I’ll be moving to this in the future.

RestKit – This library not only deals with retrieving data, it will also map it into Core Data. Pretty cool, and if you have need to cache data locally it would be worth looking at.

JSON

SBJson – A very nice JSON parser. It’s simple to use and includes handy categories for NSString and NSDictionary. It’s very simple to create a parser and operate on the results, just like you would an NSDictionary.

SBJsonParser* jsonParser = [[SBJsonParser new] autorelease];
id jsonObject = [jsonParser objectWithString:jsonString];

JSONKit – This is a parser I only recently discovered, and it’s known to be fast and efficient. It’s also super easy to use because of, you guessed it, categories. There’s a real nice one added to NSString.

NSDictionary* response = 
[[request responseString] objectFromJSONString];

See how easy that is to use? You simply invoke objectFromJSONString to get a fully parsed result jammed into an NSDictionary.

By Rob Fahrni

Husband / Father / Developer

One reply on “Objective-C REST and JSON”

Comments are closed.