"message":null,
"code":1,
"datum":[
{
"id":"1499787682425865217",
"name":"城市广场1期",
"path":"1,1499787682425865217",
"type":2
},
{
"id":"1499800930126660608",
"name":"城市广场2期",
"path":"1,1499800930126660608",
"type":2
},
{
"id":"1499802323835159556",
"name":"城市花园1期",
"path":"1,1499802323835159556",
"type":1
},
{
"id":"1499802526269047810",
"name":"城市花园2期",
"path":"1,1499802526269047810",
"type":1
}
]
}
如上是我从服务器上获取的Json数据,我用iOS自带的解析API解析的,但是有用MJExtension对解析出来的数据进行转化处理,以便我能够访问到datum数组中的数据,代码如下:
NSURL * url = [NSURL URLWithString:@"http://192.168.10.167:8080/getProjectCategoryList?path=&id="];
//创建请求
NSURLRequest * request = [NSURLRequest requestWithURL:url];
//创建Session
NSURLSession * session = [NSURLSession sharedSession];
//创建任务
NSURLSessionDataTask * task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
[AddressModel mj_setupObjectClassInArray:^NSDictionary *{
return@{
@"datum" : @"AddressDatum"
};
AddressModel *adm = [AddressModel mj_objectWithKeyValues:Dic];
// for(int i=0;i<10;i++)
// {
// cell.textLabel.text = [[adm.datum objectAtIndex:i] name];
// }
}];
[task resume];
我之前是在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
这个函数中执行的解析数据的操作,完了直接对一个个cell赋值,但是这样子会出现刚进去页面cell上显示的数据还是title,我点击之后才会在每一条的cell上显示出来
可以用kiwifruit啊,这个可方便了
kiwifruit是一款数据字典自动转换工具包,用于简化开发。这个工具箱为项目提供了一些高效、有用、开箱即用的特性,使用它可以有效地节省开发时间。 支持各种数据库或者配置文件,扩展方便,配置方便。
开源地址 :https://gitee.com/137879802/kiwifruit