gpt4 book ai didi

ios - 如何在ios中获取并显示Json Array数据

转载 作者:行者123 更新时间:2023-11-28 18:17:05 25 4
gpt4 key购买 nike

您好,我是项目中 ios 的初学者,我试图获取低于 Json 数组数据的数据,但它显示异常(如 -[__NSArrayM objectForKey:]:无法识别的选择器发送到实例 0x7be53f80)做了什么我在这里做错了请帮助我,这里的数据已成功加载到我的主 arrayList

我的 json 格式:-

  final respone dictionary(
{
Name = " ";
id = 0;
},
{
Name = "PREMIER DIM OUT";
id = 10;
},
{
Name = "PRADO COLLECTION";
id = 15;
},
{
Name = "PURE WALLS 6";
id = 16;
},
{
Name = PLATINA;
id = 17;
},
{
Name = "SARMASIK LEATHER";
id = 19;
},
{
Name = "PICASA COLLECTION";
id = 21;
},
{
Name = "3PASS BLACK OUT-SLOT LOT";
id = 25;
},
{
Name = ABYSS;
id = 26;
},
{
Name = ABYSSION;
id = 27;
},
{
Name = "ACC BOOK MODERN ELEMENT 2";
id = 28;
},
{
Name = "ACCESSORIES ROUSES 342";
id = 29;
},
{
Name = ACE;
id = 30;
},
{
Name = "ACHILLES (PAZZION)";
id = 31;
}
)
my code:-
------------

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

NSString * allDataDictionbary = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];

NSDictionary * responseString = [allDataDictionbary JSONValue];

NSLog(@"final respone dictionary%@",responseString);

NSMutableArray * mainArray = [[NSMutableArray alloc]init];
[mainArray addObject:responseString];

for (int i = 0; i<mainArray.count; i++) {


NSDictionary *BatchDict = [mainArray objectAtIndex:i];

NSString * name = [BatchDict objectForKey:@"Name"];
NSString * Id = [BatchDict objectForKey:@"id"];

[NameArray addObject:name];
[IdArray addObject:Id];
}


NSLog(@"so finally name array%@",NameArray);
NSLog(@"so finally Id array%@",IdArray);
}

最佳答案

您将数组作为字典是错误的。您正在将一个数组添加到数组中,并将这个添加的数组视为字典。

您只需要枚举 JSON 数组对象..

如果还没有收到,请发布完整回复,我会帮助您!!!

关于ios - 如何在ios中获取并显示Json Array数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34179374/

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