无法使用JSON.Framework从目标c中的json消息中获取结果

时间:2011-05-22 03:16:45

标签: objective-c json json-framework

我正在尝试使用json.framework读取json消息。该消息是会议详细信息的嵌套集合。我的愿望是迭代思考所有会议并创建本地会议对象,并从消息中读取详细信息。我看到获得json结果中的15个会议的列表但是无法从结果中获得单个值。

这是我的示例代码。我正在使用一个文件作为json消息,这样我就不必让服务器参与这个测试了。可以下载json消息here

-(void)TestParse:(NSString *)response
{
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"conference_calls" ofType:@"json"];
    NSString *fileContent =[[NSString alloc]initWithContentsOfFile:filePath];

    parser = [SBJsonParser new];
    NSArray *results = [parser objectWithString:fileContent];

    NSLog(@"Number of itmems in the results: --> %i", [results count]);

    for(NSDictionary *conf in results){

        //Load local objects with the values of the Conf info.

        NSLog(@"This the description %@ ",[c valueForKey:"phone_number"]);

        NSLog(@"Number of Items in Dic: %i",[conf count]);

        NSLog(@"File contents: %@",[conf description]);
    }

1 个答案:

答案 0 :(得分:1)

json的结构是一个字典数组。但是每个字典只有一个名为“conference_call”的密钥,该密钥的值为另一个字典,其中包含该调用的所有详细信息。

所以这样的事情应该有效:

for (NSDictionary* call in results) {

    // get the actual data for this call
    NSDictionary *callDetails = [call objectForKey:@"conference_call"];

    NSLog (@"Location is %@", [callDetails objectForKey:@"location"]);
}

希望有所帮助。