0

I am creating the API data via PHP and it creates unicode characters not correctly.

For example ü returned as \u00fc

On ASIFormDataRequest I have tried to parsed it correctly but I couldnt manage to do it. What I ve tried so far are:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setResponseEncoding:NSUTF8StringEncoding];    
[request addRequestHeader:@"content-type" value:@"text/json; charset=utf-8"];

I am wondering how can I parse the unicode characters correctly?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
birdcage
  • 2,638
  • 4
  • 35
  • 58
  • 1
    Be aware that `ASIHttpRequest` is deprecated and should not longer be used. – rckoenes Apr 13 '15 at 14:56
  • ü "LATIN SMALL LETTER U WITH DIAERESIS" is \u00fc in UTF-16. In UTF-8 it is 0xc3 0xbc. There is a mis-match between the character encoding and specifying "charset=utf-8". – zaph Apr 13 '15 at 15:19
  • I tried charset=utf-16 also but didnt work. – birdcage Apr 13 '15 at 16:58
  • http://stackoverflow.com/questions/16078747/how-do-i-properly-encode-unicode-characters-in-my-nsstring. See in this first they convert string to data and after apply utf8 encoding – Bhoomi Jagani Apr 13 '15 at 17:03

1 Answers1

0

Solution 1: set defaultResponseEncoding when creating ASIFormDataRequest.

request.defaultResponseEncoding = NSUTF8StringEncoding;

Solution 2: set responseEncoding before calling responseString.

- (void)requestFinished:(ASIHTTPRequest *)request {
    request.responseEncoding = NSUTF8StringEncoding;
    NSLog(@"%@", request.responseString);
}
jqgsninimo
  • 6,562
  • 1
  • 36
  • 30