【发布时间】:2013-05-16 14:44:14
【问题描述】:
我对此进行了广泛的搜索,但到目前为止我找不到与我的问题相匹配的问题。我有一个“独特”的 JSON 输出并试图在 Objective-C 中解析它。
首先,这是我必须解析的 JSON:
{
"code": 1,
"req": {
"123": [ //this can be different all the time
{
"item_id": "44",
"item_value": "the value",
"item_code": "21z"
},
{
"item_id": "45",
"item_value": "another value",
"item_code": "l30"
}
]
}
}
如上所示,“req”下的“123”可能会有所不同,所以我无法在我的 Objective-C 中硬编码那里的值。
到目前为止,我一直在尝试使用 NSMutableDictionary 来接收 HTTP 响应:
NSMutableDictionary dict = [NSJSONserializationWithData:responseData options:options error:&error];
NSArray *array = [[dict objectForKey@"req"];
但是从这里我不知道如何指定变量 (123) 键.. 因为它每次都可能不同。
【问题讨论】:
-
你保证“req”字典中只有一个对象吗?
-
req 中不能有多个对象。
标签: objective-c json key