频道栏目
首页 > 资讯 > IOS > 正文

iOS reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x60800

17-09-11        来源:[db:作者]  
收藏   我要投稿

iOS reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x60800。

一、源代码

NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];

NSLog(@"dic === %@",dic);

打印结果:dic === {
len = 69;
list = (
{

//是字段数据

}

for (NSDictionary * subDic in dic[@"list"]) {

NSLog(@“遍历数据”);

}

如果后台数据格式修改不是dic[@"list”]),就是崩溃报错如下:

reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x60800025e840'

二、解决方案
 
解决方法一:

NSMutableArray *topLevelArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

NSDictionary *dict = topLevelArray[0];

for (NSDictionary * subDic in dict) {

NSLog(@“遍历数据”);

}

解决方法二:

如果您想要检查你的什么,你可以使用 isKindOfClass:像这样:

id jso = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

if (jso == nil) {

// Error. You should probably have passed an NSError ** as the error

// argument so you could log it.

} else if ([jso isKindOfClass:[NSArray class]]) {

NSArray *array = jso;

// process array elements

} else if ([jso isKindOfClass:[NSDictionary class]]) {

NSDictionary *dict = jso;

// process dictionary elements

} else {

// Shouldn't happen unless you use the NSJSONReadingAllowFragments flag.

}

相关TAG标签
上一篇:Python: PS 图像调整--亮度调整
下一篇:枚举类
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站