2015-11-20 41 views
0

我需要將NSMutableArray從JSON轉換爲NSArray。我加載了JSON並將其放入NSMutableArray中。NSMutableArray從數組從json

NSMutableArray *banner = [[NSMutableArray alloc] init]; 
banner = [responseObject objectForKey:@"banner"]; 

這是循環測試:

for(int i = 0; i < [slider count]; i++) { 
     NSLog(@"%@", [[banner objectAtIndex:i] objectForKey:@"resim"]);  } 

這是日誌從JSON:

(
     { 
     id = 1; 
     resim = "http://localhost/sample_Files/banner_api/1.jpg"; 
    }, 
     { 
     id = 2; 
     resim = "http://localhost/sample_Files/banner_api/2.jpg"; 
    }, 
     { 
     id = 3; 
     resim = "http://localhost/sample_Files/banner_api/3.jpg"; 
    } 
) 

我要定這一切要像下面的NSArray:

NSArray *allImages = @[@"http://localhost/sample_Files/banner_api/1.jpg",@"http://localhost/sample_Files/banner_api/2.jpg",@"http://localhost/sample_Files/banner_api/3.jpg"]; 

我該怎麼做?

回答

0
NSMutableArray * muArr = [NSMutableArray new]; 
for(NSDictionary * dict in yourMuArr) { 
    [muArr addObject:dict[@"resim"]]; 
} 
NSArray * allImages = [NSArray arrayWithArray:muArr];