OData and NSJSONSerialization

If you’re like me, a long time .NET developer that finally also became iOS Developer, most likely you’ll use .NET to create server-side API/backend to serve iOS apps. If yes, you may use OData or WCF Data Services to implement such backend. Long before ASP.NET Web API came along, OData is the easiest way to create API.

OData can output JSON, even though it outputs in XML by default. As we know, we simply add/change “Accept” header in our HTTP request to “application/json” to get JSON responses. iOS SDK has built-in JSON parsing support since iOS 5 by using NSJSONSerialization class. All seems a perfect combination, while┬áoccasionally┬áit’s not.

Continue reading OData and NSJSONSerialization

Consuming and Parsing JSON Service in iOS 5 – The Easy Way

Let’s say I want to get tweets from Twitter.

  • I send HTTP request to Twitter with “Accept” header set to “application/json”
  • Receive returned JSON and parse it
  • Do whatever I want with parsed JSON

Above code uses two API provided only in iOS 5 or later:

  • Asynchronous and block-based handler NSURLConnection
  • NSJSONSerialization

You don’t need any third party libraries.