ios stringWithContentsOfURL with encoding?
I have a 开发者_运维技巧problem using "stringWithContentsOfURL" to get source page of a web(chinese) Thinking using "NSUTF8StringEncoding" but didn't work(got null for result). My code looks like this
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.morningstar.com.tw/download_pdf_2-1.aspx"] encoding:NSUTF8StringEncoding error:nil];
NSLog(@"html = %@",string);
replaced "NSUTF8StringEncoding" by "NSASCIIStringEncoding", did get a result but words are scrambled.
Thanks for the help!
You need a different encoding:
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingDOSChineseTrad);
You can also use kCFStringEncodingDOSChineseSimplif
for simplified chinese. Use encoding
in place of NSASCIIStringEncoding
or the other standard ones.
See the documentation for more encodings if these do not work properly.
精彩评论