我有一个我无法处理的问题。
在我的应用程序中,我从JSON中的Web服务获取数据。它是UTF8编码的,当我填写UITableView时一切正常(NSLog返回重音符号:“\ u00e9”但我的UITableView显示它像:“é”)。
但是当我在detailTextLabel中设置相同的数据时,它不会将“\ u00e9”转换为“é”......
尝试了编码的一些技巧,但没有说服力。
解析方法:
- (NSDictionary*)fetchedData:(NSData *)responseData {
NSError* error;
self.json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
return self.json;
}
-(void)executeParsingWithUrl:(NSURL*)anUrl{
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:anUrl];
NSString *authStr = [NSString stringWithFormat:@"%@:%@",[[NSUserDefaults standardUserDefaults] stringForKey:@"username_ws"], [[NSUserDefaults standardUserDefaults] stringForKey:@"password_ws"]];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [Base64 encode:authData]];
[urlRequest setValue:authValue forHTTPHeaderField:@"Authorization"];
NSError *requestError = NULL;
NSHTTPURLResponse *response = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&requestError];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:responseData waitUntilDone:YES];
}
恢复:
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
JsonParsing *getJson = [[JsonParsing alloc] init];
[getJson executeParsingWithUrl: leUrl];
self.duration = [NSString stringWithFormat:@"%@",[[getJson.json objectForKey:@"objects"]valueForKey:@"libel"]];
});
提前致谢!
答案 0 :(得分:2)
我感谢其他人的管理。 我的cell.detailTextLabel我用过这个:
cell.detailTextLabel.text = [NSString stringWithCString:[myText cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding];