Search code examples
cocoa-touchnsstringutf8-decode

Incorrect decoding of known UTF-8 string from server


In my application, I am getting some string values from a server, but I'm not ending up with the right string.

بسيط this is the string from server side, but what I am getting is بسÙØ·

I tried to test the response string in an online decoder:

http://www.cafewebmaster.com/online_tools/utf8_encode

It is UTF-8 encoded, but I couldn't decode the string on the iPhone side.

I took a look at these Stack Overflow links as reference

Converting escaped UTF8 characters back to their original form
unicode escapes in objective-c
utf8_decode for objective-c

but none of them helped.


Solution

  • SOLVED the issue from this link

    Different kind of UTF8 decoding in NSString

    NSString *string = @"بسÙØ·";

    I tried

    [NSString stringWithUTF8String:(char*)[string cStringUsingEncoding:NSISOLatin1StringEncoding]]
    

    this method

    Thank You.