gpt4 book ai didi

ios - 如何在以下字典中获取美国的所有城市?

转载 作者:行者123 更新时间:2023-12-01 19:15:54 24 4
gpt4 key购买 nike

我下面有这本字典,我想访问特定国家的所有城市。因此,如果我在下面选择美国,则希望访问休斯顿的达拉斯。例如,我想到了以下功能,但不确定如何获取所有城市的国家/地区。

-(NSArray*) fetchCitiesFromLocationDictionary:(NSMutableDictionary *)locationDictionary usingCountry:(NSString *)country
{


}


{
509f3a914d026b589ba3a090 = {
coordinates = {
latitude = "29.76429";
longitude = "-95.3837";
};
country = USA;
id = 509f3a914d026b589ba3a090;
name = Houston;
state = Texas;
};
509f3b3a4d026b589ba3a091 = {
coordinates = {
latitude = "3.138722";
longitude = "101.686849";
};
country = Malaysia;
id = 509f3b3a4d026b589ba3a091;
name = "Kuala Lumpur";
};
509f475b4d026b589ba3a093 = {
coordinates = {
latitude = "32.803468";
longitude = "-96.769879";
};
country = USA;
id = 509f475b4d026b589ba3a093;
name = Dallas;
state = Texas;
};
}

最佳答案

尝试这样的事情:

NSDictionary *dictionary = [NSDictionary dictionary];
NSMutableArray *cities = [NSMutableArray array];
for (NSDictionary *individualDictionary in dictionary)
{
if ([[individualDictionary objectForKey:@"country"] isEqualToString:@"USA"])
[cities addObject:[individualDictionary objectForKey:@"name"]];
}

关于ios - 如何在以下字典中获取美国的所有城市?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367662/

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