我有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/

10-12 14:33