简体   繁体   中英

how to convert into NSString?

I am stuck with utf-8 to NSString. I am getting this data from web service :

{
    Description = "漢字仮名交じり文";
    Images =
    (
        {
            imageName = "0_25_07_2012_10_32_54_1343212374.jpg";
        }
    );
    Time = "11:00 am";
    actId = 290;
    actTitle = "漢字仮名交じり文";
}

Now how can i convert 名 (名) this kind of code to NSString ?

I'm pretty sure something is wrong with your web service. If the web service response is JSON or XML data, then the JSON or XML parser should have decoded the special characters. Since it did not, the web service mistakenly uses a double decoding of characters outside the ASCII range.

The best solution is to fix it at the source, ie in the web service.

If you can't, then use the stringByDecodingHTMLEntities method from this NSString category , eg:

NSString* textValue = [response objectForKey: @"Description"];
textValue = [textValue stringByDecodingHTMLEntities];

You will have to run each string property through this method.

The codes that you have here are called numeric character references. They have nothing directly to do with UTF8 in general.

See this question for a summary of answers to your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM