Search code examples
iosjsonios6ios6.1

How to get json data in ios 6.1 xcode 4.6


How do I get data for the link: https://itunes.apple.com/us/rss/topalbums/limit=10/json using ios6.1 xcode 4.6.
Most of the codes are for ios5 and few use jsonKit. But does ios has any inbuilt json parsing now?

I am looking forward for using only for ios6.1 and not older versions.


Solution

  • NSError *requestError = NULL;
    NSDictionary *myDict = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&requestError];
    if (requestError){
        //An error occurred.
    }
    

    The return type of +JSONObjectWithData is id. It could return an NSDictionary or an NSArray. Choose whichever fits your JSON data structure.

    Where responseData is, well, the data from your response. If you have a string you want to parse, convert it to NSData: https://stackoverflow.com/a/6188605/985050