Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

ios - Saving data in NSDictionary from NSDictionary

Here is my JSON format data which I have parsed and save in A dictionary called NSDictionary *dic.I have an other NSDicitonary named dic1 in which I just want to store data from //1 to //3 how can i do that ?please Help ?

//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"
}]

This is How i have done.?

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];

    }
 }

My point is in allKeys whole data is saved instead of saving whole data from //0 to //3 i just need data from //02 to //03 stored in some Dictionary.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming you realize this is array:

    NSArray *a = [[NSArray alloc] init];
    NSMutableArray *a1 = [[NSMutableArray alloc] init];

    for(int i = 1; i < a.count; i++) {
       [a1 addObject: a[i]];
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...