我正在使用 JSON 接收响应,然后尝试将其保存在 NSDictionary
中。我在同一个应用程序的近 12 个克隆中使用了相同的代码,并且运行良好。但是,在我的一个应用程序中,我无法做到这一点。
NSDictionary *resultsDictionary = [jsonString JSONValue];
NSString *statusString = [resultsDictionary objectForKey:@"status"];
这是一个简单的两行代码,可以正常工作,但我不知道这次发生了什么。可能是我的 JSON 框架没有正常工作。但我在 JSONValue
中得到了这个:
{
"status": "Success",
"data": [
{
"userName": "abc@gmail.com",
"first_name": "ABC",
"last_name": "XYZ",
"gender": "male",
"userid": 1,
"membershipStatus": "Active",
"Saldo": 499.749,
"Avatar": "no_photo.gif",
"uniqueCode": "abc234abc234",
"registerKey": "abc543abc534",
"eMail": "abc@gmail.com"
}
]
仍然,当我执行它时,我得到这个错误:
[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance
因为 resultDictionay
是空的。
为什么 resultDictionay
是空的?有什么建议吗?
最佳答案
[jsonString JSONValue];
通过此链接在您的项目中设置目标依赖项
JSONValue 是来自 SBJson 的第三方库。 Apple 内置了使用这种方法转换 json 的框架
用这个
NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
关于ios - 无法将 JSONValue 写入 NSDictionary - JSON 框架无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21846654/