gpt4 book ai didi

ios - 如何从 'http://country.io/names.json' 获取字典和数组

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

我是 json 的新手。

我想知道如何从中获取代码和国家名称

http://country.io/names.json

并将其显示在标签中。

为此我只想知道 objectForKEy 和 valueForKey。

我想要这样的输出,

Before Country Name, I want Country Code from API

我想要这样的输出

IN  India

在我的表格 View 中

我的单元格中有两个标签,一个用于代码,另一个用于名称。

最佳答案

喜欢

NSMutableArray *Name = [[NSMutableArray alloc] init];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://country.io/names.json"]];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

for (NSString *findkey in [json allKeys]) {
//[Name addObject:[json objectForKey:findkey]];
[Name addObject:[NSString stringWithFormat:@"%@ %@",findkey,[json objectForKey:findkey]]];
}

NSLog(@"Name==%@",Name);

你得到类似的输出

enter image description here

关于ios - 如何从 'http://country.io/names.json' 获取字典和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39165154/

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