我需要你的幫助。我可以正確解析graph.facebook.com/me/feed JSON,但是我無法通過graph.facebook.com/me/conversations來完成。你能幫我麼?這是我如何得到飼料的最後一條消息解析JSON Facebook對話XCODE
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions
error:nil];
NSLog(@"json %@", json);
NSDictionary *items = [json objectForKey:@"data"];
// NSDictionary *item = [items objectAtIndex:1];
NSLog(@"items %@", items);
NSMutableArray *story = [NSMutableArray array];
for (NSDictionary *item in items)
{
if([item objectForKey:@"message"] || [item objectForKey:@"message"] != nil || [[item objectForKey:@"message"] length]>0)
{
[story addObject:[item objectForKey:@"message"]];
}
else{
NSLog(@"no message");
}
}
NSLog(@"story %@", story);
NSString *lastMessage = [story objectAtIndex:0];
NSLog(@"lastmessage received is %@", lastMessage);
你能幫我嗎?謝謝
編輯:我得到這個錯誤在NSString * lastMessage = [故事objectAtIndex:0];
*終止應用程序由於未捕獲的異常 'NSRangeException',原因: '* - [__ NSArrayM objectAtIndex:]:索引0超出界限爲 空數組' *第一擲調用堆棧:(0x341fc2a3 0x3aede97f 0x34147b75 0xc3a1d 0x3add2d91 0x3c22c11f 0x3c22fecf 0x3c22fdc1 0x3c23091d 0x3c230ac1 0x3ae54a11 0x3ae548a4)的libC++ abi.dylib:終止叫做拋出異常
的NSLog從 「項目」 是以下:
(
{
"can_reply" = 1;
id = "t_id.xx5719286166414";
"is_subscribed" = 1;
link = "http://www.facebook.com/messages/?action=read&tid=id.xx5719286166414";
"message_count" = 4;
messages = {
data = (
{
"created_time" = "2012-11-30T17:53:00+0000";
from = {
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
};
id = "m_msg.fe83b318fa94e6bbcc90a9a52fa4645b01";
message = "Questo \U00e8 un messaggio";
tags = {
data = (
{
name = inbox;
},
{
name = messenger;
},
{
name = read;
},
{
name = "source:mobile";
}
);
};
to = {
data = (
{
email = "[email protected]";
id = 100004765716168;
name = "AccountDevelopment Development";
},
{
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
}
);
};
},
{
"created_time" = "2012-11-29T11:49:00+0000";
from = {
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
};
id = "m_id.128631660627297";
message = "funziona?";
tags = {
data = (
{
name = inbox;
},
{
name = read;
},
{
name = "source:web";
}
);
};
to = {
data = (
{
email = "[email protected]";
id = 100004765716168;
name = "AccountDevelopment Development";
},
{
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
}
);
};
},
{
"created_time" = "2012-11-28T18:05:57+0000";
from = {
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
};
id = "m_id.141590452655798";
message = "prova messaggio";
tags = {
data = (
{
name = inbox;
},
{
name = read;
},
{
name = "source:web";
}
);
};
to = {
data = (
{
email = "[email protected]";
id = 100004765716168;
name = "AccountDevelopment Development";
},
{
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
}
);
};
},
{
"created_time" = "2012-11-28T18:04:50+0000";
from = {
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
};
id = "m_id.xx5719286166414";
message = "Ciao Francesco, come stai?";
tags = {
data = (
{
name = inbox;
},
{
name = read;
},
{
name = "source:web";
}
);
};
to = {
data = (
{
email = "[email protected]";
id = 100004765716168;
name = "AccountDevelopment Development";
},
{
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
}
);
};
}
);
paging = {
next = "https://graph.facebook.com/t_id.xx5719286166414/messages?access_token=BAABlotMxL1MBACbrnuvICOwBKjkw68ZBaqLOY2MVE6tga8xPmiF9VWH7RZAZCoZBDeSD29KWTzuze3xpjP7xb1kmfyw7VYtvGZC0E1gwgJthpZAoKoFXAYanGcBMb1qzO7SBAI3WPLcLAq7yAUpyF9NiHY0vIpsiGJZASx3eZCA83Lm18hpjmo0K97ZBSOiAoYeZCm2vYDgqq4S8jqOvZCvGZCZByNeg4ElNiSwZA1hHqdA6qrFAZDZD&limit=25&until=1354125890&__paging_token=m_id.xx5719286166414";
previous = "https://graph.facebook.com/t_id.xx5719286166414/messages?access_token=BAABlotMxL1MBACbrnuvICOwBKjkw68ZBaqLOY2MVE6tga8xPmiF9VWH7RZAZCoZBDeSD29KWTzuze3xpjP7xb1kmfyw7VYtvGZC0E1gwgJthpZAoKoFXAYanGcBMb1qzO7SBAI3WPLcLAq7yAUpyF9NiHY0vIpsiGJZASx3eZCA83Lm18hpjmo0K97ZBSOiAoYeZCm2vYDgqq4S8jqOvZCvGZCZByNeg4ElNiSwZA1hHqdA6qrFAZDZD&limit=25&since=1354297980&__paging_token=m_msg.fe83b318fa94e6bbcc90a9a52fa4645b01&__previous=1";
};
};
participants = {
data = (
{
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
},
{
email = "[email protected]";
id = 100004765716168;
name = "AccountDevelopment Development";
}
);
};
senders = {
data = (
{
email = "[email protected]";
id = 1367741936;
name = " xxx xxx";
}
);
};
snippet = "Questo \U00e8 un messaggio";
tags = {
data = (
{
name = inbox;
},
{
name = read;
},
{
name = seen;
},
{
name = "source:web";
}
);
};
"updated_time" = "2012-11-30T17:53:00+0000";
}
)
你會得到什麼錯誤? – combinatorial
我編輯了我的帖子。謝謝。 – accountDevelopment