Generally in the development will encounter Chinese garbled problem, but how to solve it becomes a problem of ours, in fact very simple, let's look at the specific method below
1.url garbled
NSString *path = [[NSString stringwithformat:@ "%@", @ "Http://news.baidu.com/n?cmd=1&class=internet&tn=rss"] Stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];
2. Garbled content
General Server encoding format are UTF8, so through the JSON parse down the data, the general Chinese is not garbled, but if the server encoding format is not UTF8, through the JSON parsing data in the Chinese is prone to garbled, how to solve this problem? generally is through transcoding to solve, but the direct transcoding, is not able to achieve the effect, for example:
[JSON stringstringbyaddingpercentescapesusingencoding:nsutf8stringencoding],This direct transcoding is not up to the effect. when parsing the data, it is possible to store the data in the NSData object before transcoding, for examplensdata*jsondata = [Requestresponsedata];nsstring*jsonstring = [[nsstringalloc]initwithbytes:[jsondatabytes]length:[jsondatalength]encoding: Nsutf8stringencoding];this solves the problem of parsing the data inside the Chinese garbled
IOS Handling Content garbled problem