嗨朋友们,我正面临着将json文件解析到uitableview的问题。 我的json文件看起来像这样:
[
{
"id": 1,
"type": "Deal Closed",
"score": 100,
"createdAt": "2014-10-03T08:10:10.000Z",
"updatedAt": "2014-10-03T08:10:10.000Z"
},
{
"id": 2,
"type": "Followers",
"score": 10,
"createdAt": "2014-10-03T08:10:28.000Z",
"updatedAt": "2014-10-03T08:10:28.000Z"
}
]
我的编码在这里..
static NSString *CellIdentifier = @"Leader";
NSString *firstname = [[promoArray objectAtIndex:indexPath.row] objectForKey:@"type"];
NSString *lastname = [[promoArray objectAtIndex:indexPath.row] objectForKey:@"score"];
cell.lblPrice.text=[jsonDict valueForKey:@"type"];
cell.lblDesc.text=[jsonDict valueForKey:@"score"];
它抛出异常..解析时。我需要解析从json文件到Uitable视图的类型和分数。
答案 0 :(得分:1)
调整为:
cell.lblPrice.text=jsonDict[indexPath.row][@"type"];
cell.lblDesc.text= jsonDict[indexPath.row][@"score"];