【问题标题】:Php web service - results are not showing right on AndroidPHP Web 服务 - 结果在 Android 上显示不正确
【发布时间】:2013-08-06 14:57:23
【问题描述】:

我有一个 PHP Web 服务来控制我的所有数据库函数,这些函数在 JSON 对象中给出响应 因为我使用的是希伯来语文本,所以我正在以 UTF-8 的方式对所有内容进行编码 - 但我所有的希伯来语文本都失去了空格..

这是我在 Android 中的 http 响应代码:

private JSONObject getApiResponse(HttpResponse response) throws Exception
{
    //get response status line
    StatusLine statusLine = response.getStatusLine();
    //if statue line is ok - read the response and return it
    if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
        HttpEntity entity = response.getEntity();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        entity.writeTo(out);
        out.close();                
        return new JSONObject(new String(out.toString().getBytes(),"UTF-8"));
    }
    return null;
}

这是我对 php 的回应:

    $api = new api();
    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
    echo utf8_encode($api -> processRequest()); //processRequest() always returns JSON object
  • 所有数据表均为 UTF 8
  • PHP mysqli 设置为 UTF 8

这是来自服务的响应示例:

{"events":[
{"Event_Code":"10212208",
 "Event_Name":"\u05de\u05e1\u05d9\u05d1\u05ea \u05e9\u05e9        
               \u05e9\u05e0\u05d9\u05dd                             
               \u05dc\u05d1\u05d0\u05e8\u05e7\u05d9",
  "Place":"\u05d4\u05e2\u05e6\u05de\u05d0\u05d5\u05ea 84 \u05d7\u05d9\u05e4\u05d4",
  "Start_Time":"2013-08-22 21:00:00",
  "End_Time":"2013-08-23  05:00:00",
  "Facebook_Id":"741688125",
   "User_Name":"Name"}]}

有什么想法吗??

【问题讨论】:

  • 我是瞎子还是...\u05ea \u05e9...里面有空格?不知道你在做什么......
  • 它确实......但在我的安卓屏幕中,这些空间消失了
  • 也许我应该用 URL 等其他编码来包装内容?
  • 所以这可能不是 php/json 问题,因为那里存在空格。您必须查看您的 android 端显示代码。

标签: php android utf-8


【解决方案1】:

好的。找到了解决方案:

阅读 Marc B 的评论后,我重新检查了我的代码,发现我的一个文本视图结合了预设的英文单词和希伯来语的 Web 服务响应......

这导致视图由于某种原因被损坏...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 2015-10-30
    • 2017-02-19
    相关资源
    最近更新 更多