Dealing with special characters like (ö, Ä, é, ß) in iOS

寵の児 提交于 2019-12-08 00:21:54

问题


I am fetching data from URL, and this data contains special characters, such as in the name Désirée.

I want to display this in my TableView cell, but when I display it, it looks like this: Dösiröe.

How do I make it display correctly?

Fetch data

NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:URL] encoding: NSStringEncodingConversionAllowLossy error:nil];
SBJSON *parser = [[SBJSON alloc] init];
dictShow = [parser objectWithString:jsonString error:nil];
arr=[dictShow copy];

Display Data in TableView

cell.textLabel.text = [arr objectAtIndex:indexPath.row];

回答1:


just use NSUTF8StringEncoding instead of NSStringEncodingConversionAllowLossy like....

NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:URL] encoding:NSStringEncodingConversionAllowLossy error:nil];


来源:https://stackoverflow.com/questions/16166176/dealing-with-special-characters-like-%c3%b6-%c3%84-%c3%a9-%c3%9f-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!