不需要的字符而不是阿拉伯字符
我在我的项目中使用Web服务。我编写了一个Web服务客户端方法, 当我调用这个方法时,我得到包含数据的 json 对象。然后我在 jsp 中提取该对象并使用它 显示。问题是:我需要在这里显示一些阿拉伯字符 从 json 对象获取。当我将其发送到浏览器时,它正在显示 صـيشلية ســد مــــأرء 类似字符而不是阿拉伯字符。
JSON 对象:
"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",
}
]}
在 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>
<%}} %>
当我运行此 JSP 时,我收到不需要的字符而不是阿拉伯字符。我哪里做错了?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其放在 JSP 的顶部。
这将指示服务器将 JSP 中的数据以 UTF-8 格式写入和发送,并且还将添加一个响应标头,指示客户端(浏览器)将数据解释为 UTF-8。否则将使用系统的默认值(通常是不包含阿拉伯字符的 ISO-8859-1)。
另请参阅本文,了解 Unicode 问题的背景信息和解决方案:Unicode - 如何获得正确的字符?
Put this in top of your JSP.
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?
这可能与页面的编码有关。您肯定需要
unicode
编码(其中包括那些特殊字符),而您可能正在使用标准utf-8
(实际上不需要)。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 standardutf-8
(which does not).