如何用json发布

时间:2011-06-14 11:21:07

标签: iphone json post

您好我想为词典

设置以下键值
{
        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;
                }
            );
        };

我想发布comments ={ data ={ id = , name = }}

我使用了以下代码

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

[variables setObject:@"Good Afternoon" forKey:@"message"];


NSLog(@"%@",variables);

FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"id/comments" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);

但这不起作用....我如何在评论对象中发布消息

1 个答案:

答案 0 :(得分:0)

请检查以下代码:

NSMutableDictionary *comments = [[NSMutableDictionary alloc] init];
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
NSMutableDictionary *from = [[NSMutableDictionary alloc] init];

[from setObject:@"100001507678574" forKey:@"id"];
[from setObject:@"Widevision Dev" forKey:@"name"];

[data setObject:from forKey:@"from"];


[comments setObject:data forKey:@"comments"];


NSLog(@"%@",comments);

FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"id/comments" withPostVars:comments];