gpt4 book ai didi

ios - initWithObjectAndkeys 如何在 iOS 中使用变量

转载 作者:行者123 更新时间:2023-11-29 02:16:25 25 4
gpt4 key购买 nike

initWithObjectAndkeys如何使用变量,我想循环遍历类别中的项目,请帮助

如果我这样使用 NSArray

data = [saved_result valueForKey:@"data"];
NSLog(@"%@",[data valueForKey:@"category"]);

NSArray *myArray = [[NSArray alloc]initWithObjects:data, nil];
for (id tempObject in myArray) {
NSLog(@"Single element: %@", tempObject);

}

这里是NSArray类型变量保存数据的内容,有助于大家理解代码。保存的结果 =

(
{
data = {
amount = 10;
category = Food;
dealid = 28;
enddate = "2016-12-31";
retailername = mukesh;
startingdate = "2015-01-10";
title = gter;
};
msg = "deals found";
status = true;
},
{
data = {
amount = 10;
category = Shopping;
dealid = 44;
enddate = "2016-12-31";
retailername = divya;
startingdate = "2015-01-10";
title = welcome;
};
msg = "deals found";
status = true;
}
)


2015-02-24 17:09:57.985 Raott[3316:59975] Single element: (
{
amount = 10;
category = Food;
dealid = 28;
enddate = "2016-12-31";
retailername = mukesh;
startingdate = "2015-01-10";
title = gter;
},
{
amount = 10;
category = Shopping;
dealid = 44;
enddate = "2016-12-31";
retailername = divya;
startingdate = "2015-01-10";
title = welcome;
},
{
amount = 859;
category = Shopping;
dealid = 53;
enddate = "2016-12-31";
retailername = mukesh;
startingdate = "2015-01-10";
title = ghk;
},
{
amount = 50;
category = Shopping;
dealid = 64;
enddate = "2016-12-31";
retailername = mukesh;
startingdate = "2015-01-10";
title = "new deal";
},
{
amount = 12;
category = Shopping;
dealid = 68;
enddate = "2016-12-31";
retailername = mukesh;
startingdate = "2015-01-10";
title = hello;
},
{
amount = 213;
category = Food;
dealid = 69;
enddate = "2016-12-31";
retailername = mukesh;
startingdate = "2015-01-10";
title = fgfdg;
}
)

最佳答案

您保存的结果是 NSArrayarrResult ,因此我们将循环通过它。

for(NSDictionary *dictObject in arrResult)
{
//Get Data Dictionary
NSDictionary *dictData = [dictObject valueForKey:@"data"];
//Now have data so traverse
for (NSString*strkey in dictData) {
id value = [dictData objectForKey:strkey];
NSLog(@"id = %@",value);
}
}

关于ios - initWithObjectAndkeys 如何在 iOS 中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28694339/

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