不需要的字符而不是阿拉伯字符

发布于 2024-10-03 19:40:57 字数 1649 浏览 1 评论 0原文

我在我的项目中使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

客…行舟 2024-10-10 19:40:57

将其放在 JSP 的顶部。

<%@ page pageEncoding="UTF-8" %>

这将指示服务器将 JSP 中的数据以 UTF-8 格式写入和发送,并且还将添加一个响应标头,指示客户端(浏览器)将数据解释为 UTF-8。否则将使用系统的默认值(通常是不包含阿拉伯字符的 ISO-8859-1)。

另请参阅本文,了解 Unicode 问题的背景信息和解决方案:Unicode - 如何获得正确的字符?

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?

别想她 2024-10-10 19:40:57

这可能与页面的编码有关。您肯定需要 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 standard utf-8 (which does not).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文