Search code examples
objective-ciosjsoncocoa-touchrestkit

How to convert a Json String into a NSArray?


I am currently trying to convert the JSON Representation of some Objects into an NSArray. I used RestKit to get the Response through our API and now I want to convert the RKResponse into an Array of Objects. How can I do this ?


Solution

  •  NSData* data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        NSArray *values = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];  // if you are expecting  the JSON string to be in form of array else use NSDictionary instead
    

    The above code works good for iOS 5 and above