我在解析我的 JSON 时遇到了麻烦。我想知道如何在“sel”对象中获取 value1 和 value2(参见下面的 JSON)。我一直在这样做:
SBJsonParser *jsonParser = [[SBJsonParser alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: url]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSMutableDictionary *json = [jsonParser objectWithString: json_string];
//NSLog(@"%@", json);
for(NSDictionary *dict in [json valueForKey:@"sel"])
{
NSLog(@"%@", [dict objectForKey: @"value1"]);
}
这给了我一个错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x88314c0'
我如何达到 value1 和 value2?我的 JSON 看起来像这样:
{
content = {
details = {
desc = "lorem";
name = lorem;
options = {
name = lorem;
};
};
};
};
sel = {
other = (
);
content = {
id = 95;
"date" = "2013";
price = 100;
};
value1 = 100;
value2 = 100;
};
}