iOS 崩溃问题[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x10b15a470

1.服务器返回的数据类型

{

    responseMessage =     {

        accountid = “”;

        data = “”;

        errorCode = 0000;

        msg = success;

        “msg_help” = “”;

        “msg_other” = “”;

        “msg_statistics” =         (

        );

        sourceCode = “”;

        token = “”;

    };

    responseType = 1;

}

2.崩溃日志

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x10b15a470’

3.崩溃原因

打印

[info objectForKey:@”responseMessage”],可以正常打印,但是打印字典responseMessage下的key为 [@”data”],程序就会崩溃,仔细分析后发现原因是我解析的后台数据中responseMessage 字典下的 data这个 value 一共有三种类型 :1.字典,2.空字典,3.字符串.

4.解决办法

NSString *imgString = @””;

            if ([[[info objectForKey:@”responseMessage”] objectForKey:@”data”] isKindOfClass:[NSDictionary class]]) {

                imgString = [[[info objectForKey:@”responseMessage”] objectForKey:@”data”]objectForKey:@”imageName”];

            }

对 data 进行判断,

1.如果data 的类型为字典,则对数据进行相应的处理

2.如果data 的类型为非字典,则对数据进行其他操作.

分享到: 更多
Separator image Posted in IOS.