我在解析JSON的时候,到最后一步将字典内容遍历到model的时候就会出现null和重复数据,之前的每一步都是正确的,用朋友自用服务器的api测试有这个问题,我还用了百度APIStore里的新闻API,也是同样的问题,请问我是哪里做错了,请各位赐教,谢谢!
下面是代码,用的AFNetworking,JSON里有5个数组,最底下是控制台截图,用for循环和被注释掉的for in,都是一样的问题
[manager POST:@"地址不便透露,抱歉" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"成功");
if ([responseObject isKindOfClass:[NSDictionary class]]) {
NSArray *jData = [responseObject objectForKey:@"array"];
//NSLog(@"%@",jData);
for (NSDictionary * dict in jData)
{
NSArray * keys=[dict allKeys];
JKey * jKey=[[JKey alloc]init];
/*
for (NSString * str in keys) {
//对对象的属性一一赋值 KVC
[jKey setValue:[dict objectForKey:str] forKey:str];
if ([dict objectForKey:str] > 0) {
[self.testArray addObject:jKey];
}
}
*/
for (NSInteger i=0; i<keys.count; i++) {
[jKey setValue:[dict objectForKey:keys[i]] forKey:keys[i]];
NSLog(@"jKey=%@",jKey.coverpath);
}
}
}