我是iOS開發人員。我想解析我的這個JSON數據到數組中第一個數組包含所有數據和第二個數組僅包含-demopage:數組值。如何解析iOS中的嵌套字典JSON數據?
status: "success",
-data: [
{
mid: "5",
name: "October 2014",
front_image: "http://www.truemanindiamagazine.com/webservice/magazineimage/frontimage/01.jpg",
title: "October 2014",
release_date: "2014-10-01",
short_description: "As the name suggest itself 「Trueman India」 will cover icons of India. Our national Magazine 「Trueman India」 is an expansion to our business, i",
current_issue: 0,
-demopage: [
{
link: "http://www.truemanindiamagazine.com/webservice/magazineimage/pageimage/2014/10/01-1413806104.jpg",
page_no: "1"
},
{
link: "http://www.truemanindiamagazine.com/webservice/magazineimage/pageimage/2014/10/2-1413806131.jpg",
page_no: "2"
},
{
link: "http://www.truemanindiamagazine.com/webservice/magazineimage/pageimage/2014/10/3-1413806170.jpg",
page_no: "3"
}
]
}
]
這裏我主要解釋主要是數據我想在這裏另一個數組在我的一個陣列和demopage鍵值數據keey值我的兩個數組是self.imageArray和self.imagesa這裏我的代碼對於
- (void)viewDidLoad
{
[super viewDidLoad];
[self.collectionView registerNib:[UINib nibWithNibName:@"CustumCell" bundle:nil] forCellWithReuseIdentifier:@"CellIdentifier"];
dispatch_async(kBgQueue, ^{
data = [NSData dataWithContentsOfURL: imgURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
-(void)fetchedData:(NSData *)responsedata
{
NSMutableArray *imagesArray = [[NSMutableArray alloc]init];
if (responsedata.length > 0)
{
NSError* error;
self.json = [NSJSONSerialization JSONObjectWithData:responsedata options:kNilOptions error:&error];
if ([[_json objectForKey:@"data"] isKindOfClass:[NSArray class]])
{
NSArray *arr = (NSArray *)[_json objectForKey:@"data"];
[self.imageArray addObjectsFromArray:arr];
[self.storeTable reloadData];
}
self.storeTable.hidden=FALSE;
for (index=0; index<[self.imageArray count]; index++)
{
for(NSDictionary *dict in self.imageArray)
{
imagesArray = [dict valueForKey:@"demopage"];
self.imagesa = imagesArray;
}
NSLog(@"New Demo page array %@",self.imagesa);
}
}
然後我得到我的數據鍵值,它是好的,但我只有最後一個索引意味着在這裏我的數據鍵包含三個-demopage鍵和我只得到最後-demopage鍵值我希望所有-demopage鍵值self.imagesa請給我解決方案。 也是我的web服務鏈接Link
您可以添加您的完整WebServices數據 – 2014-11-05 10:23:40