http://xtremeinspection.com/new2you4kids/app/android/get_category_brand.php
上面是 JSON 的 URL。
我想在“PARENT_CATEGORY_ID”=“0”的 xcode 上显示数据。
我使用了以下编码:
-(void) loadJSON
{
loadJSONData = [NSURL URLWithString:mainURL];
NSLog(@"Fetch JSON URL : %@",loadJSONData);
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
loadJSONData];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData
{
NSError* error;
json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
adultJSON = [json objectForKey:@"category"];
NSLog(@"Data: %@", adultJSON);
NSDictionary *typeData = [json objectForKey:@"category"];
categTypeArray = [[NSMutableArray alloc] initWithCapacity:0];
for (NSDictionary *types in typeData)
{
if([[NSString stringWithFormat:@"%@",[adultJSON valueForKey:@"PARENT_CATEGORY_ID"]] isEqualToString:@"0"])
{
[categTypeArray addObject:[types valueForKey:@"PARENT_CATEGORY_ID"]];
}
}
NSLog(@"Data: %@", adultJSON);
NSLog(@"Category Data: %@", categTypeArray);
}
但是categTypeArray 返回null。
我应该使用哪种方法?