本文介绍了的IOS目标C解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试解析此json,似乎无法弄清楚.
Trying to parse this json and cannot seem to figure it out.
这是我的代码,但是我在NSLog上得到了一个SigAbt:
Here is my code, but I get a SigAbt on the NSLog:
- (NSMutableArray *) getVariants:(NSString *)variantJson
{
NSMutableArray *variants = [[NSMutableArray alloc] init];
NSLog(@"Variant JSON: %@", variantJson);
NSArray *vars = [variantJson valueForKeyPath:@"variants"];
for (id var in vars)
{
NSLog(@"description: %@",[var objectForKey:@"description"]);
}
return variants;
}
传入变量json的变量:variantJson是上面发布的JSON.
The json coming in to variable: variantJson is the above posted JSON.
推荐答案
iOS不会透明地解析JSON.您需要通过实际的JSON解析器库(例如 SBJson )运行字符串. (BSD许可)或者您可以使用内置的 NSJSONSerialization (如果您使用的是OS 5或更高版本).
iOS doesn't parse JSON this transparently; you need to run your string through an actual JSON parser library, like SBJson. (BSD-licensed) Or you can use the built-in NSJSONSerialization if you're targeting OS 5 or later.
这篇关于的IOS目标C解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!