NSDictionary到UITableView

我有一个JSON请求得到这个:

bills = ( { id = 1; name = "Cursus Nibh Venenatis"; value = "875.24"; }, { id = 2; name = "Elit Fusce"; value = "254.02"; } ); 

我正在为它创build一个NSDictionary。

我正在使用JSONKit,我想知道如何填充我的UITableView这个值? 谢谢你的帮助!

编辑

 NSLog(@"my dictionary = %@", resultsDictionary); my dictionary = { bills = ( { id = 1; name = "Cursus Nibh Venenatis"; value = "875.24"; }, { id = 2; name = "Elit Fusce"; value = "254.02"; } ); } 

看起来像在结果字典中,你有一个数组。 数组中的每个对象都是一个字典。 试用下面的代码。

 NSArray *billsArray = [resultsDictionary objectForKey:@"bills"]; 

在您的tableView数据源方法tableView: cellForRowAtIndexPath:[[billsArray objectAtIndex:indexPath.row] objectForKey:@"name"] tableView: cellForRowAtIndexPath:

看起来你的bills字典是由一些较小的字典组成的。 你可以像这样访问它;

 get the top Dictionary bills. access each dictionary inside (for loop, etc) and create an array load table view data from previously created array 

编辑*

 NSDictionary *billsDictionary = [NSDictionary dictionaryWithDictionary:[resultsDictionary objectForKey:bills]]; NSMutableArray *dataSource = [[NSMutableArray alloc]init]; //make this an ivar and your tabelView's data source. for(NSDictionary *dict in billsDictionary){ [dataSource addObject:dict]; } [tableView reloadData]; //then in your tableView cell cell.textLabel.text = [[NSString stringWithFormat:@"%@", [[dataSource objectAtIndex:indexPath.row]objectForKey:@"name"]] //Repeat for whatever else you want to add to the cell (subtitle, image, etc.) Hope this helps.