开发者

How to print json ouput on console

I am using Facebook graph API and getting its result in json format.. I am able to print some result but confused in others..

  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";
},

I can print this icon, id , link by this code

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"]);

.. also get this

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"]);

        }

But how can I parse this 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 =                     {
                     开发者_如何学Go   id = 100001507678574;
                        name = "Widevision Dev";
                    };
                    id = "100001507678574_164163733643881_1822143";
                    message = hmmm;
                }
            );
        };

please help


Well, I see a clear json object here. I would take example of SBJSON where all the JSON is parsed into NSDictionary object, where application, caption, comments are the keys. The object for comment again forms a dictionary with keys; count, data. Once you get to the data you have an array of the entire data and so this array contains multiple dictionary. Getting each dictionary within the array of data should solve your problem. Best of luck.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜