问题描述
|
我正在使用Facebook graph 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;
}
);
};
请帮忙
解决方法
好吧,我在这里看到一个清晰的json对象。我以SBJSON为例,其中所有JSON都解析为NSDictionary对象,其中“ 5”是键。用于评论的对象又构成了一个带有键的字典。
count,data
。到达“ 7”后,您将拥有一个完整数据数组,因此该数组包含多个字典。在数据数组中获取每个字典应该可以解决您的问题。祝你好运。