Recently, I was working on a network application and received that XML is GBK encoded. I used utf8 to encode it and returned the nil result. It is obvious that the encoding method is wrong and the GBK encoding method is used.
The method is as follows:
View plaincopy to clipboardprint?
- UnsignedLongEncode = cfstringconvertencodingtonsstringencoding (kcfstringencodinggb_18030_2000 );
- Nsdata * responsedata = [Request responsedata];
- Nsstring * STR = [[nsstring alloc] initwithdata: responsedata encoding: encode];
- Ttdprint (@"Html = % @", STR );
Unsigned long encode = encode (kcfstringencodinggb_18030_2000); nsdata * responsedata = [Request responsedata]; nsstring * STR = [[nsstring alloc] initwithdata: responsedata encoding: encode]; ttdprint (@ "html = % @", STR );
References:
Http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
See: Click to open the link