开发者

Problem getting JSON contents with JSONValue

I am using the objective-c json framework to parse some json from the lighthouse api - http://stig.github.com/json-framework/

I've used the framework before with other apis with no issues although i seem to have come to a dead end when trying to grab the results from the lighthouse api using JSONValue.

It appears the value is being returned incorrectly:

NSArray *results = [json_string JSONValue];

for (NS开发者_JS百科Dictionary *project in results){
    NSLog(@"project found");
}

This loop only runs once although i know there are atleast 7 objects for it to itterate through in the JSON string. project is also being set as a string and not a NSDictionary, i know this as calling objectForKey on project causes an error.

[NSCFString objectForKey:]: unrecognized selector sent to instance 

I'm pretty stumped here and hope this isn't an issue with the string being returned from the Lighthouse api and i am just trying to get the contents incorrectly, my json string is here: http://pastie.org/1390233


The parser's behavior is correct. The dictionary results contains only 1 key with the name projects which is an array. To loop through each individual project, you need to enumerate this projects property.

NSArray *projects = [results objectForKey:@"projects"];

for(NSDictionary *item in projects) {
    NSDictionary *project = [item objectForKey:@"project"];
    // now project should have the desired keys
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜