Krunal
Krunal

Reputation: 6490

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

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];

Upvotes: 2

Views: 1274

Answers (1)

Nirav Gadhiya
Nirav Gadhiya

Reputation: 6342

just use NSUTF8StringEncoding instead of NSStringEncodingConversionAllowLossy like....

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

Upvotes: 6

Related Questions