Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Json String into a NSArray? [closed]

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 ?

like image 566
Sebastian Boldt Avatar asked Oct 30 '12 12:10

Sebastian Boldt


2 Answers

 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

like image 52
AppleDelegate Avatar answered Nov 06 '22 23:11

AppleDelegate


Try importing RestKit/RKJSONParserJSONKit.h. Then use try the method objectFromString:error:. To get a NSDictionary representation. From the NSDictionary you can get the array.

like image 45
LuisEspinoza Avatar answered Nov 06 '22 22:11

LuisEspinoza