gpt4 book ai didi

ios - 当某些键动态更改时如何从字典中获取值

转载 作者:行者123 更新时间:2023-11-29 03:01:11 24 4
gpt4 key购买 nike

我有一个包含 20 个对象的可变数组。每个对象都有给定的格式

{

"NONE-NONE-ABCD-RECD" = {
Count =
{
bird = "10";
animal = "4";
};

Type = "NONE-NONE-ABCD-RECD";
};

}

键值NONE-NONE-ABCD-RECD对于不同的对象会有所不同。有时会变成NONE-NONE-NONE-NONEABCD-PQWE -MNBW-POWE等我需要找到每个对象的鸟和动物。当键改变时我怎样才能得到计数。

最佳答案

试试这个,

NSArray *allKeys = [elementDict allKeys]; //elementDict array object
if ([allKeys count] > 0) {
NSDictionary *objectDict = [elementDict objectForKey:[allKeys objectAtIndex:0]];
NSDictionary *countDict = [objectDict objectForKey:@"Count"];
//from countDict you can access values
NSString *bird = [countDict valueForKey:@"bird"];
NSString *animal = [countDict valueForKey:@"animal"];
}

关于ios - 当某些键动态更改时如何从字典中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286887/

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