2011-06-14 74 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