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 ?
问问题
12750 次
2 回答
22
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
上面的代码适用于 iOS 5 及更高版本
于 2012-10-30T13:01:05.883 回答
2
尝试导入 RestKit/RKJSONParserJSONKit.h。然后使用 try 方法 objectFromString:error:。获取 NSDictionary 表示。从 NSDictionary 你可以得到数组。
于 2012-10-30T13:01:59.440 回答