Server----WebService
Back to JSON data iOS parsing error:
Error Domain=nscocoaerrordomain code=3840 "Unable to convert data to string around character 56." Userinfo={nsdebugdescription=unable to convert data to string around character 56.}
Code = 3840 Error
I wrote the JSON in the document data local parsing succeeded, but the iOS request resolution has been reported this error
Two times the result is different, then the request to the JSON data to print out, found that the network request JSON data byte stream and the local data parsing print a different stream ( Note: I TMD a comparison, the previous data, the back of the same. You are right to see if your own is also this error )
cause Analysis : WebService returns the GB2312 encoded data. ios resolves the data to be converted to UTF8 encoded format!
Solution: convert data from GB2312 format to UTF8 !
Conversion code:
-(NSString *) Gb2312toutf8: (NSData *) data{
Nsstringencoding enc =cfstringconvertencodingtonsstringencoding (kcfstringencodinggb_18030_2000);
NSString *retstr = [[NSString alloc] Initwithdata:data Encoding:enc];
return retstr;
}//Convert the encoding format to NSString now
Call the method above:
NSString *datastr = [self gb2312toutf8:data];
Convert DATASTR to UTF8 encoded data
NSData *data = [datastr datausingencoding:nsutf8stringencoding];
Okay , we can parse data.
Native IOS parsing json problem