gpt4 book ai didi

iphone - 重新排列 NSArray 和 NSDictionary 条目

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

我有带有 nsdictionary 对象的数组,例如:

({"someKey" = "title";
"name" = "someName";
},
{"someKey" = "title";
"name" = "anotherName";
}
{"someKey" = "newTitle";
"name" = "someName";
}
)

请帮我按以下格式排序:

({"someKey" = "title";
"names": (
{"name" = "someName"},
{"name" = "anotherName"}
)
},
{"someKey" = "newTitle";
"names": (
{"name" = "someName"}
)
}
)

谢谢..

最佳答案

据我从你的问题中了解到,你想将单个对象挑选到一个字典对象中..

NSArray *yourArray=.... /* array which contains this data: ({"someKey" = "title";
"name" = "someName";
},
{"someKey" = "title";
"name" = "anotherName";
}
)*/
NSMutableDictionary *newDictionary=[[NSMutableDictionary alloc]init];

for(int i=0;i<[yourArray count];i++){
[newDictionary setObject:[yourArray objectAtIndex:i] forKey:@"names"];
}

关于iphone - 重新排列 NSArray 和 NSDictionary 条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12937324/

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