2011-06-14 63 views
0

打印输出中的JSON我使用Facebook的图形API,并获取其JSON格式的结果..我能打印一些结果,但在别人迷茫..如何在控制台

application =   { 
     id = 142759389130183; 
     name = iphonemini; 
    }; 
    caption = "widevision.co.in"; 
    "created_time" = "2011-06-14T07:56:38+0000"; 
    from =   { 
     id = 100001507678574; 
     name = "Widevision Dev"; 
    }; 
    icon = "http://www.facebook.com/images/icons/hidden.gif"; 
    id = "100001507678574_173203589406562"; 
    link = "http://widevision.co.in/"; 
    message = "Good Afternoon"; 
    name = "Check It out"; 
    type = link; 
    "updated_time" = "2011-06-14T07:56:38+0000"; 
}, 

我可以打印此图标,ID,这个代码链接

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me/feed" withGetVars:nil]; 


    NSLog(@"method called"); 
    //parse our json 
    SBJSON *parser = [[SBJSON alloc] init]; 
    NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];  

    [parser release]; 

    //NSString *feed; 
    // NSString *feed2; 
    NSMutableArray *feed =(NSMutableArray *) [facebook_response objectForKey:@"data"]; 

    // NSMutableArray *feed1=(NSMutableArray *) [feed valueForKey:@"type"]; 


    NSLog(@"Feed %@" ,feed); 

    NSLog(@"Message is %@ ",[feed valueForKey:@"icon"]); 

    NSLog(@"Name is %@",[feed valueForKey:@"name"]); 

..也得到这个

from ={ 
    id= ; 
    name = ""; 
    } 


NSMutableArray *streams = (NSMutableArray *)[feed valueForKey:@"from"]; 



    // loop over all the stream objects and print their titles 
     int index; 
     NSMutableDictionary *stream; 

     for (index = 0; index < [feed count];index++) { 
      stream = (NSMutableDictionary *)[streams objectAtIndex:index]; 



      NSLog(@"Message is %@:",[stream valueForKey:@"name"]); 

     } 

但我怎么能解析这个comments = { }....

{ 
     application =   { 
      id = 136664723060869; 
      name = Iphoneapp; 
     }; 
     caption = "bit.ly"; 
     comments =   { 
      count = 2; 
      data =    (
           { 
        "created_time" = "2011-06-14T07:39:45+0000"; 
        from =      { 
         id = 100001507678574; 
         name = "Widevision Dev"; 
        }; 
        id = "100001507678574_164163733643881_1822049"; 
        likes = 1; 
        message = hi; 
       }, 
           { 
        "created_time" = "2011-06-14T08:17:31+0000"; 
        from =      { 
         id = 100001507678574; 
         name = "Widevision Dev"; 
        }; 
        id = "100001507678574_164163733643881_1822143"; 
        message = hmmm; 
       } 
      ); 
     }; 

请帮助

回答

0

好了,我在这里看到一个清晰的JSON对象。我将以SBJSON为例,将所有JSON解析为NSDictionary对象,其中application, caption, comments是关键字。用于评论的对象再次形成具有键的字典; count, data。一旦你到达data你有一个整个数据的数组,所以这个数组包含多个字典。获取数据阵列中的每个字典应该可以解决您的问题。祝你好运。

+0

好的谢谢你的回复 – iProgrammer 2011-06-14 10:10:08

+0

我在post方法有问题...我如何在注释中设置消息和id – iProgrammer 2011-06-14 10:42:11