这是我的代码,我想在UITableview上显示Json数据。我的应用程序崩溃由于这个原因' - [__ NSCFString objectForKey:]:无法识别的选择器发送到实例0x10a860840。我是Json的新手。
- (void)viewDidLoad
{
[super viewDidLoad];
NSError *error;
NSString *url_string = [NSString stringWithFormat: @"http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"];
NSURL *blogURL = [NSURL URLWithString:url_string];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSDictionary *dataDictionary = [NSJSONSerialization
JSONObjectWithData:jsonData options:0 error:&error];
//NSLog(@"Data : %@",dataDictionary);
for (NSDictionary *bpDictionary in dataDictionary)
{
NSobjectClass *currenHotel = [[NSobjectClass alloc]initWithcountrycode:[bpDictionary
objectForKey:@"countrycode"] name:[bpDictionary objectForKey:@"name"] toponmyName:[bpDictionary objectForKey:@"toponmyName"] population:[bpDictionary
objectForKey:@"population"]];
[self.objectHolderArray addObject:currenHotel];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
return [self.objectHolderArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Cell1 *cell = [self.JsonTableview dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
NSobjectClass *currentHotel = [self.objectHolderArray
objectAtIndex:indexPath.row];
cell.countryCode.text = currentHotel.countrycode;
cell.countryName.text = currentHotel.name;
cell.countrytype.text = currentHotel.toponmyName;
cell.population.text = currentHotel.population;
return cell;
}
请检查我的代码。