gpt4 book ai didi

ios - JSON 响应中 NSDictionary 中的对象数组 - objective-c

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:54:46 25 4
gpt4 key购买 nike

我试图从 NSDictionary 的 JSON 响应中获取对象列表,然后将其存储在 NSMutableArray 中,但它一直只给我数组中的一个对象,Can请帮我提供示例代码,

这是 json 响应:

{
"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}]"
}
]
}

我正在尝试获取键 txs 值中的列表。

这就是我想要做的:

-(NSDictionary *)getListOfExtraData:(NSMutableArray *)extras{
NSDictionary *array = [[NSDictionary alloc] init];
for (NSDictionary *dictionary in extras) {
if([[dictionary valueForKey:@"key"] isEqualToString:@"txs"])
array = [dictionary objectForKey:@"value"];
}
if (array != nil && array.count > 0)
return array;
return nil;
}

最佳答案

JSON 数据无效,因为 value 中有一个对象

你应该像这样发送你的 JSON

{

"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
}
]
}
]
}

关于ios - JSON 响应中 NSDictionary 中的对象数组 - objective-c ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171890/

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