Unwanted characters instead of arabic characters
I am using a webservice in myproject.I wrote a webservice client method,
when I call this method I get the json object which has the data. Then I extract that object in jsp and using it
to display. the problem is: I need to display some arabic characters here which I am
getting from json object.when I send it to browser it is displaying
صـيدلية ســد مــــأرب
like characters instead of arabic characters.
JSON Oject:
"results": [
{
"attributes": {
"OBJECTID": "35",
"FACILITYTYPE": "Pharmacy",
"FACILITYSUBTYPE": "24 Hr Pharmacy",
"COMMERCIALNAME_E": "SADD MAARAB PHARMACY",
"COMMERCIALNAME_A": "صـيدلية ســد مــــأرب",
"TELEPHONE": "5832625",
"FAX": "5833266",
},
"geometryType": "esriGeometryPoint",
},
{
"attributes": {
"OBJECTID": "1",
"FACILITYTYPE": "Pharmacy",
"FACILITYSUBTYPE": "24 Hr Pharmacy",
"COMMERCIALNAME_E": "GAYATHY HOSPITAL PHARMACY",
"COMMERCIALNAME_A": "صيدلة مستشفى غياثي",
"TELEPHONE": "28741666",
"FAX": "28742008",
},
"geometryType": "esriGeometryPoint",
}
]}
开发者_开发知识库displaying data in jsp:
<% for (Object object : results) {
JSONObject jobj = (JSONObject)object;
if ( jobj != null && jobj.containsKey( "attributes" ) )
{
JSONObject att= (JSONObject) jobj.get("attributes");
%>
<tr ><td ><span><%= att.get("COMMERCIALNAME_E") %></span></td>
<tr ><td ><span><%= att.get("COMMERCIALNAME_A") %></span></td>
<td ><span><%= att.get("TELEPHONE") %></span></td>
<td ><span><%= att.get("FAX") %></span></td>
</tr>
<%}} %>
When I run this JSP, I am getting unwanted characters instead of Arabic characters. Where I did wrong?
Put this in top of your JSP.
<%@ page pageEncoding="UTF-8" %>
This will instruct the server to write and send the data in JSP as UTF-8, and it will also add a response header which instructs the client (browser) to interpret the data as UTF-8. Otherwise the system's default will be used (which is often ISO-8859-1 which doesn't contain Arabic characters).
See also this article for background information and solutions to Unicode problems: Unicode - How to get the characters right?
This could have something to do with the encoding of the page. You will certainly need a unicode
encoding (which includes those special characters) whereas you probably are using the standard utf-8
(which does not).
精彩评论