【发布时间】:2015-10-05 05:05:34
【问题描述】:
我在使用模型从 json 获取数据并将数据显示到我的应用程序时有点困惑。
我有这种 json 数据:
{
result
[
{
key : value
key : value
key : value
}
{
key : value
key : value
key : value
}
]
}
我正在尝试这种代码:
json = [[NSMutableArray alloc]init];
NSError *writeError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:responseObject options:NSJSONWritingPrettyPrinted error:&writeError];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&writeError];
json = dic[@"Result"];
int i;
for (i = 0; i <= json.count; i++)
{
NSMutableArray *array = json[i];
[json enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop)
{
// Dim = [[DimEntityFull alloc]initWithJSONDictionary:obj];
saveSearch = [[SaveSearchMaster alloc]initWithJSONDictionary:obj];
} ];
}
我正在使用“AFNetworking”,我正在尝试获取数据并存储到模型类中,然后显示到自定义单元格标签。
我怎样才能得到它。
谢谢。
【问题讨论】:
-
您是否尝试过在提取的每个阶段记录数据?
-
是的,但它对我不起作用。我对如何存储到模型类有点困惑。
-
我知道 arrayOfRecords = [jsonData objectForKey:@"result"];然后 cell.lblName.text = [[arrayOfRecords objectAtIndex:indexPath.row]valueForKey:@"name"];是正确的流程。但是使用模型类我怎样才能得到相同的结果?
标签: ios objective-c json afnetworking