How to convert a Json String into a NSArray? [clos

2020-04-11 10:45发布

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 ?

2条回答
该账号已被封号
2楼-- · 2020-04-11 11:18
 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

查看更多
Anthone
3楼-- · 2020-04-11 11:43

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.

查看更多
登录 后发表回答