1. Convert the requested data to
2. take the first nine bytes of an XML file
nsdata * XMLData = [self. Data subdatawithrange:nsmakerange(0,+)];
3. decoding with UTF-8 encoding
nsstring *xmlstr = [[nsstring alloc] initwithdata: XMLData encoding: Nsutf8stringencoding];
// search GB2312, if found, change GB2312 to Utf-8 (PS: replacement string)
if ([Xmlstr rangeofstring:@ "\" gb2312\ "" options:nscaseinsensitivesearch] . Location! = nsnotfound)
{
NSLog(@ " encountered:GB2312 encoding founded. is changing GB2312 to utf-8 ");
nsstringencoding enc = cfstringconvertencodingtonsstringencoding(kcfstringencodinggb_18030_ );
nsstring *utf8str = [[nsstring alloc] initwithdata:self. Data encoding: enc];
UTF8STR = [Utf8str stringbyreplacingoccurrencesofstring:@ "\" gb2312\ "" withstring:@ "\" Utf-8\ "" options:nscaseinsensitivesearch range:nsmakerange(0 ,Max)];
New data that can be parsed properly
nsdata *newdata = [utf8str datausingencoding:nsutf8stringencoding];
}
The processing method of xml-gb2312 Web page encoding encountered