问题
In my Android application I get JSON response string from a PHP url. from the response I get some hotel names with apostrophe
, I get '
character instead of apostrophe
. How can I parse the hotel with special characters in android? I can see the apostrophe in the browser but could not see in android logcat.
I have tried jresponse = URLEncoder.encode(jresponse,"UTF-8");
but I could not get apostrophe
for hotel name.
This is the one of the hotel name in the response.
I see the following in browser.
{"id":12747,
"name":"Oscar's",
....
}
But in the logcat:
id 12747
name Oscar's
回答1:
Use the decoder instead of encoder. URLDecoder.decode(jresponse,"UTF-8")
回答2:
Use ISO-8859-2 when you create the URLEncodedEntity that you send off. You can set this as a parameter in the constructor.
Without a specified charset, you are probably sending the data in UTF-8/UTF-16 (most common) which the server is interpreting in a different way.
EDIT: It looks like ISO-8859-2 doesn't support ñ. You may have to change something server-side. http://en.wikipedia.org/wiki/ISO/IEC_8859-2
回答3:
You can try Html class. eg :- jresponse = Html.fromHtml(jresponse);
来源:https://stackoverflow.com/questions/22301169/android-parse-special-characters-in-json-response