0

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

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

我正在为它创建一个 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";
    }
);
}
4

2 回答 2

1

看起来您的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.
于 2012-07-31T16:58:43.167 回答
0

似乎在结果字典中,您有一个数组。Array 中的每个对象都是字典。试用以下代码。

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

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

于 2012-07-31T18:07:26.027 回答