首页 > 解决方案 > NSDictionary - 无法识别的选择器发送到实例 - 错误

问题描述

我正在尝试解析从 Web 服务返回的 JSON。响应 JSON 看起来像这样 {"API_Count":"17"}

这是我的代码..只是想获得价值(17)。关键值。这是我的代码..“基本”的东西一定是错的。我得到错误

**[NSTaggedPointerString objectForKey:]: unrecognized selector sent to instance**


***Any ideas??***


NSData *jsonData = [responseObject dataUsingEncoding:NSUTF8StringEncoding];
NSError *err = nil;

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&err];

for (NSDictionary *item  in json )
{
    NSObject *val = [item objectForKey:@"API_Count"];

    // ERROR !!! [NSTaggedPointerString objectForKey:]: unrecognized selector sent to instance 0xa32b4de1b0d02c49


}

标签: nsdictionary

解决方案


NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData 选项:NSJSONReadingAllowFragments 错误:&err];

NSInteger val = [[json objectForKey:@"API_Count"] intergerValue];


推荐阅读