的IOS目标C解析JSON [英] ios objective c parsing json
问题描述
尝试解析此json,似乎无法弄清楚.
Trying to parse this json and cannot seem to figure it out.
{ description =描述变式1"; id = 4; 价格="25.0"; }, { description ="Variant 2 Description"; id = 5; 价格="50.0"; }, { description ="Variant 3 Description"; id = 6; 价格="75.0"; }
{ description = "Description Variant 1 "; id = 4; price = "25.0"; }, { description = "Variant 2 Description "; id = 5; price = "50.0"; }, { description = "Variant 3 Description"; id = 6; price = "75.0"; }
这是我的代码,但是我在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许可)或者您可以使用内置的
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!