辞書のJSON配列(http://www.cjs-design.nl/json.php)をテーブルビューに解析する時点で固まっています。私はちょうどそのタイトルの最初の、悪い数字を後でdetailviewsを表示したい。テーブルビューで辞書のJSON配列を解析する
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *rawJson = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.cjs-design.nl/json.php"]];
// No connection or file not found
if ([rawJson length] == 0) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Foutmelding" message:@"De URL kon niet worden gevonden" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
[rawJson release];
return;
}
SBJSON *parser = [[[SBJSON alloc] init] autorelease];
// 1. get the top level value as a dictionary
NSDictionary *jsonObject = [parser objectWithString:rawJson error:NULL];
// 2. get the object as an array
NSArray *list = [jsonObject objectForKey:@"book"];
// 3. iterate the array; each element is a dictionary.
for (NSDictionary *book in list)
{
// that contains a string for the key "title"
NSString *title = [book objectForKey:@"title"];
cell.textLabel.text = title;
}
return cell;
}