2016-11-16 3 views
-3

Voici mes données au format JSON que j'ai analysées et enregistrées dans un dictionnaire appelé NSDictionary * dic.J'ai un autre NSDicitonary nommé dic1 dans lequel je veux juste stocker les données de // 1 à// 3 comment puis-je faire cela? S'il vous plaît aider?Enregistrement de données dans NSDictionary à partir de 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" 
}] 

Voici comment j'ai fait.

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

    } 
} 

Mon point est AllKeys toute les données sont enregistrées au lieu d'enregistrer les données de l'ensemble // 0 à 3 // i juste besoin des données de // 02-03 // stockés dans certains dictionnaire.

+2

C'est un tableau, pas un dictionnaire – dan

+0

Monsieur est-il un @ Dan solluttion pour cela? –

+0

On ne sait pas ce que vous voulez réellement faire. Vous devriez mettre à jour votre question avec un code pertinent. Montrez quels dictionnaires vous avez et comment vous souhaitez prendre des données d'un et le mettre dans l'autre. – rmaddy

Répondre

1

En supposant que vous réalisez c'est un tableau:

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

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

Merci !! Enfin eu le point! –

+1

Ou [subarrayWithRange] est plus soigné – Gruntcakes