gpt4 book ai didi

ios - 无法解析基本的 JSON - iOS

转载 作者:行者123 更新时间:2023-11-28 20:12:10 24 4
gpt4 key购买 nike

我有一个 iOS 应用程序,它从 Facebook API 下载并解析一个 JSON 文件。

但是,每当我尝试解析它时,我的应用程序就会崩溃并收到此错误:

2013-11-06 15:31:41.473 JSONTESTER[10881:70b] -[__NSCFDictionary objectAtIndex:]: unrecognized 
selector sent to instance 0x10d01bd30
2013-11-06 15:31:41.476 JSONTESTER[10881:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x10d01bd30'

这是我要解析的简单 JSON 文件:

{


"id": "xxxxxxxxxx",
"name": "Dan Sadjadian",
"home": {
"data": [
{
"id": "xxxxxxxxxxxxxxxxxxxxxx",
"from": {
"name": "Jane Smith",
"id": "xxxxxxxxxxxxxxx"
},
"message": "deadline is only 16 days!!! Where are you guys!!!!!!!!! Please shall we start!!!!!",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/xxxxxxx/posts/xxxxxxxxxxx"
},
{
"name": "Like",
"link": "https://www.facebook.com/xxxxxxxxx/posts/xxxxxxxxxxxx"
}
],
"privacy": {
"value": ""
},
"type": "status",
"status_type": "mobile_status_update",
"created_time": "2013-11-06T14:40:23+0000",
"updated_time": "2013-11-06T14:40:23+0000"
},
],
},
}

这是我的代码,应该可以工作....

cell.username.text = [[[[[facebook_array objectAtIndex:index] valueForKey:@"data"] objectAtIndex:0] valueForKey:@"from"] valueForKey:@"name"];

如您所见,我正在尝试访问“from”中的“name”,它位于“home”中的“data”数组中。

我做错了什么?

谢谢,丹。

最佳答案

应该是

NSArray *arrData=[MAIN_DICTIONARY objectForKey:@"data"];

NSDictionary *data=[arrData objectForIndex:0];

NSDictionary *from=[data objectForKey:@"from"];

NSLog(@"Name = %@", [from objectForKey:@"name"]);

我希望它能帮助你理解它是如何工作的。

关于ios - 无法解析基本的 JSON - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19816424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com