`
luckliu521
  • 浏览: 258831 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

IPhone下GBK转UTF-8

 
阅读更多
先把数据转成二进制,然后再转成字符串,见下面代码,开头那两句

- (void)didReceiveData:(NSData *)data {
CFStringRef gb2312Str = CFStringCreateWithBytes(NULL, 
[data bytes], 
[data length], 
kCFStringEncodingGB_18030_2000, 
false); 
if(NULL == gb2312Str){
NSLog(@"create CFStringRef fail");
}
else{
NSString *gb2312NSString = (NSString *)gb2312Str; 
data = [gb2312NSString dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"has get data %@",gb2312Str);
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:YES];
[parser setShouldResolveExternalEntities: YES];
NSError *parseError = [parser parserError] ;
//parseError = [parser parserError];
if (parseError) {
NSLog(@"parser parserError");
}

[parser parse];
[parser release];
CFRelease(gb2312Str); 

}
[spinner stopAnimating];
[spinner removeFromSuperview];
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics