本文主要是介绍iOS reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x60800,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//联系人:石虎 QQ: 1224614774昵称:嗡嘛呢叭咪哄
一、源代码
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.
}
谢谢!!!
这篇关于iOS reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x60800的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!