Cannot parsing Json to NSDictionary

自闭症网瘾萝莉.ら 提交于 2019-12-02 08:20:48

From the debugger screenshot is seems that the server is (for whatever reason) returning "nested JSON": responseDict[@"d"] is a string containing JSON data again, so you have to apply NSJSONSerialization twice:

NSError *errorJson = nil;
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData: data options:0 error: &errorJson];
NSData *innerJson = [responseDict[@"d"] dataUsingEncoding:NSUTF8StringEncoding];
NSMutableDictionary *innerObject = [NSJSONSerialization JSONObjectWithData:innerJson options:NSJSONReadingMutableContainers error:&errorJson];
NSString *usr = [innerObject objectForKey:@"user"];

If you have the option, a better solution would be to fix the web service to return proper JSON data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!