1.在我们通过网路请求请求到数据后,进行解析,解析后的数据有字典,有数组,我们就需要进行接收,而接收直接用“=”常常遇到接受不到数据问题,所以如下解决方案出现。
字典和数组在init方法中必须进行初始化,否则赋不上值。
a.当是数组时,我们是这样接收的:
[_array addObjectsFromArray:[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]];
b.当是字典时,我们时这样做的;
[_dic setDictionary:[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]];
2.数组和字典相互接收中常用方法:
a.字典——数组
NSDictionary *dic =[_tableArray objectAtIndex:indexPath.row];
b.字典——字典
NSDictionary *dic = [_dic objectForKey:@"Variables"];
c.数组——数组
NSArray *arr = [_tableArray objectAtIndex:indexPath.row];
d.数组——字典
NSDictionary *dic = [_tableArray firstObject];