ios - JSON响应中NSDictionary内的对象数组- objective-c
<p><p>我正在尝试从 <code>NSDictionary</code> 的 JSON 响应中获取对象列表,然后将其存储在 <code>NSMutableArray</code> 中,但它一直只给我一个数组中的对象,可以请您帮我提供示例代码,</p>
<p>这是 json 响应:</p>
<pre><code>{
"errorCd": "00",
"desc": "Success",
"ref": 83,
"statusCode": "1",
"extraData": [
{
"key": "bal",
"value": "80"
},
{
"key": "txs",
"value": "[{\"id\":2268099999,\"amnt\":100.0,\"curr\":\"JOD\",\"sender\":\"PSPCI\",\"receiver\":\"00962799999992\",\"date\":\"Feb 1, 2016 4:03:25 PM\",\"status\":1,\"type\":5,\"fees\":0.0,\"reference\":40},{\"id\":2357099999,\"amnt\":20.0,\"curr\":\"JOD\",\"sender\":\"00962799999992\",\"receiver\":\"PSPCI\",\"date\":\"Feb 2, 2016 12:52:35 PM\",\"status\":1,\"type\":6,\"fees\":0.0,\"reference\":68}]"
}
]
}
</code></pre>
<p>我正在尝试获取键 txs 的值中的列表。</p>
<p>这就是我想要做的:</p>
<pre><code>-(NSDictionary *)getListOfExtraData:(NSMutableArray *)extras{
NSDictionary *array = [ init];
for (NSDictionary *dictionary in extras) {
if([ isEqualToString:@"txs"])
array = ;
}
if (array != nil && array.count > 0)
return array;
return nil;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>JSON 数据无效,因为 <code>value</code> 在 <code>"</code></p> 中有一个对象
<p>你应该像这样发送你的 JSON</p>
<pre><code>{
"errorCd": "00",
"desc": "Success",
"ref": 83,
"statusCode": "1",
"extraData": [
{
"key": "bal",
"value": "80"
},
{
"key": "txs",
"value": [
{
"id": 2268099999,
"amnt": 100.0,
"curr": "JOD",
"sender": "PSPCI",
"receiver": "00962799999992",
"date": "Feb 1, 2016 4:03:25 PM",
"status": 1,
"type": 5,
"fees": 0.0,
"reference": 40
},
{
"id": 2357099999,
"amnt": 20.0,
"curr": "JOD",
"sender": "00962799999992",
"receiver": "PSPCI",
"date": "Feb 2, 2016 12:52:35 PM",
"status": 1,
"type": 6,
"fees": 0.0,
"reference": 68
}
]
}
]
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - JSON响应中NSDictionary内的对象数组- objective-c ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35171890/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35171890/
</a>
</p>
页:
[1]