我很难从声明为的多级数组中提取字典:
NSArray *menuItems;
看起来像这样:
Table = (
{
MENUDESC = "HOME ";
MENUID = 1072;
NAVIGATETO = "content.aspx?item=1072&pid=0";
NAVIGATETO2 = "default.aspx?item=1072&pid=0";
PARENTMENUID = "<null>";
PROTECTED = "<null>";
parentmenuid2 = "<null>";
},
{
MENUDESC = "PRODUCTS & SERVICES";
MENUID = 1073;
NAVIGATETO = "#";
NAVIGATETO2 = "default.aspx?item=1073&pid=0";
PARENTMENUID = "<null>";
PROTECTED = "<null>";
parentmenuid2 = "<null>";
},
{
MENUDESC = "ABOUT US";
MENUID = 1074;
NAVIGATETO = "content.aspx?item=1074&pid=0";
NAVIGATETO2 = "default.aspx?item=1074&pid=0";
PARENTMENUID = "<null>";
PROTECTED = "<null>";
parentmenuid2 = "<null>";
},
{
MENUDESC = "WHAT SETS US APART";
MENUID = 1075;
NAVIGATETO = "content.aspx?item=1075&pid=0";
NAVIGATETO2 = "default.aspx?item=1075&pid=0";
PARENTMENUID = "<null>";
PROTECTED = "<null>";
parentmenuid2 = "<null>";
},
{
MENUDESC = "CASE STUDIES";
MENUID = 1126;
NAVIGATETO = "content.aspx?item=1126&pid=0";
NAVIGATETO2 = "default.aspx?item=1126&pid=0";
PARENTMENUID = "<null>";
PROTECTED = "<null>";
parentmenuid2 = "<null>";
},
{
MENUDESC = "REQUEST PROPOSAL";
MENUID = 1076;
NAVIGATETO = "content.aspx?item=1076&pid=0";
NAVIGATETO2 = "default.aspx?item=1076&pid=0";
PARENTMENUID = "<null>";
PROTECTED = "<null>";
parentmenuid2 = "<null>";
},
{
MENUDESC = CONTACT;
MENUID = 1077;
NAVIGATETO = "contactus.aspx?item=1077&pid=0";
NAVIGATETO2 = "contactus.aspx?item=1077&pid=0";
PARENTMENUID = "<null>";
PROTECTED = "<null>";
parentmenuid2 = "<null>";
}
);
}
从 JSON 创建,如下所示:
{
"Table": [
{
"MENUID": 1072.0,
"MENUDESC": "HOME ",
"PARENTMENUID": null,
"NAVIGATETO": "content.aspx?item=1072&pid=0",
"NAVIGATETO2": "default.aspx?item=1072&pid=0",
"PROTECTED": null,
"parentmenuid2": null
},
{
"MENUID": 1073.0,
"MENUDESC": "PRODUCTS & SERVICES",
"PARENTMENUID": null,
"NAVIGATETO": "#",
"NAVIGATETO2": "default.aspx?item=1073&pid=0",
"PROTECTED": null,
"parentmenuid2": null
},
{
"MENUID": 1074.0,
"MENUDESC": "ABOUT US",
"PARENTMENUID": null,
"NAVIGATETO": "content.aspx?item=1074&pid=0",
"NAVIGATETO2": "default.aspx?item=1074&pid=0",
"PROTECTED": null,
"parentmenuid2": null
},
{
"MENUID": 1075.0,
"MENUDESC": "WHAT SETS US APART",
"PARENTMENUID": null,
"NAVIGATETO": "content.aspx?item=1075&pid=0",
"NAVIGATETO2": "default.aspx?item=1075&pid=0",
"PROTECTED": null,
"parentmenuid2": null
},
]
}
我正在研究示例代码,他们使用它来提取字典:
NSDictionary *items = [menuItems objectAtIndex:indexPath.row];
但这不起作用 - 我收到错误“发送的选择器无效”。我尝试了各种方法来访问数组中的数据。但是我发现的所有研究和答案都没有帮助。
我需要像这样创建 NSStrings:
NSString *text = [[menuItems objectForKey:@"Table"] objectForKey:@"MENUDESC"];
NSString *name = [[menuItems objectForKey:@"Table"] objectForKey:@"MENUID"];