iOS 后台返回的数据gbk解析不出来
有这么一条数据,Android正常解析,浏览器正常访问,但是用OC的代码去请求却一直为null!
这次解析不出来是因为后台返回的object是gbk编码的字符串,需要通过gbk转码,转码之后再解析就OK了
NSString *responseData = responseObject; if ([responseObject isKindOfClass:[NSData class]]) { NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); NSString *gbkStr = [[NSString alloc]initWithData:responseObject encoding:gbkEncoding]; //转码之后再转utf8解析 NSData *jsonData = [gbkStr dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *requestDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil]; responseData = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; }