這裏是我的JSON格式的數據,我已經解析並保存在名爲NSDictionary * dic的字典中。我有一個名爲dic1的NSDicitonary,我只想將數據從// 1存儲到//3我該怎麼做?請幫忙?從NSDictionary保存NSDictionary中的數據
//0
[{
"about": "Mother, actor, entrepreneur, fitness enthusiast and an eternal positive thinker",
"id": "238bb4ca-606d-4817-afad-78bee2898264",
"username": "Shilpa shetty kundr"
}
//1
, {
"about": "Www.Nargisfakhri.com Instagram- @NargisFakhri Twitter- @NargisFakhri FaceBook- Nargis Fakhri ",
"id": "cda99c24-955a-4c58-a6a8-c811938df530",
"username": "Nargis Fakhri"
}
//2
, {
"description": "Celebrating Black Friday in this lovely black cut out romper and floral accessories. I love black and i think it is the easiest thing to wear when i am in doubt. So a black romper solves my dilemma of what to wear when i am short of time to decide and outfit. When you wear black add some fun accessories to keep the outfit fun and lively.",
"id": "fa6d9bdf-eae3-4d6c-a668-9be94cfaf980",
"verb": "created this story on 25 October"
},
//3
{
"description": "Today's outfit! #ootd Sheer shirts are always so sexy. Team it up with a bustier inside and it looks elegant and sexy at the same time. I wore my purple sheer shirt with an embellished maxi skirt and statement necklace. Sheer shirts looks fabulous with statement necklaces or layered chains.",
"id": "066f2bac-1fa8-44f8-b2b6-780df3324c71",
"verb": "created this story on 21 October"
}]
這就是我所做的。
NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
id allKeys = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
userIDArray=[[NSMutableArray alloc]init];
for (int i=0; i<[allKeys count]; i++) {
NSDictionary *arrayResult = [allKeys objectAtIndex:i];
if([arrayResult objectForKey:@"id"]!=NULL){
NSString *id=[arrayResult objectForKey:@"id"];
[userIDArray addObject:id];
}
}
我的觀點是allKeys整個數據被保存,而不是從// 0至3 //我只需要從// 02 //至03存放在一些字典數據保存完整的數據。
這是一個數組,而不是一本字典 – dan
@丹先生是有它的任何solluttion? –
目前還不清楚你真正想做什麼。你應該用一些相關的代碼更新你的問題。顯示您擁有的字典以及您希望如何從其中獲取數據並將其放入其中。 – rmaddy