我有问题。如何从NSData转换俄语文本?
NSURL *url = [NSURL URLWithString:@"http://pda.somesite"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setAllowCompressedResponse:YES];
[request startSynchronous];
NSLog(@"response %@",[request responseString]);
响应(null)
NSLog(@"Length %i", [[request responseData] length]);
长度11733
char * dataChar = [[request responseData] bytes];
NSLog(@"%s",dataChar);
//这里我有拉丁文,但俄语符号是这样的-ñ-Π-≤-æ-μ-æ-±-â-μ-Ω-Π-μ-Å-μ-μ -∞-ª-å-Ω-ã-º-Π-ª-å-¥-å-Π-Å-æ-≤-Å-μ-≥-æ-º-Π-Ä-∞!< /强>
NSData * newData = [NSData dataWithBytes:dataChar length:127];
取第127个字符。如果这里拿超过127的结果是空的!为什么?我在127之后没有特殊符号。如果我从127到255采用符号,这个文本也可以。
NSString * data = [[NSString alloc] initWithUTF8String:[newData bytes]];
俄罗斯simbols看起来很不错但我有127个字符长
NSString * str = [NSString stringWithUTF8String:dataChar];//str -> (null)
NSString * str127 = [NSString stringWithUTF8String:[newData bytes]];//OK but 127 characters
答案 0 :(得分:0)
替换此
char * dataChar = [[request responseData] bytes];
NSLog(@"%s",dataChar);
用这个
NSString *message = [NSString stringWithCString:[[request responseData] bytes] encoding:NSUTF8StringEncoding];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
然后你看,一切正常