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

2019-05-22 22:26发布

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条回答
SAY GOODBYE
2楼-- · 2019-05-22 23:32

just use NSUTF8StringEncoding instead of NSStringEncodingConversionAllowLossy like....

NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:URL] encoding:NSStringEncodingConversionAllowLossy error:nil];
查看更多
登录 后发表回答