【问题标题】:Sending japanese characters over JSON通过 JSON 发送日文字符
【发布时间】:2012-02-13 08:18:33
【问题描述】:

我尝试通过 json 发送日文字母,然而,返回的 json 值为"jspString":"???????"。我究竟做错了什么?谢谢!

JSONObject info = new JSONObject();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

info.put("japString", "よやかなゆひま");
nameValuePairs.add(new BasicNameValuePair("info", info.toString()));
postCard.setEntity(new UrlEncodedFormEntity(nameValuePairs));   
postResponse = postCardClient.execute(postCard);
postResponseEntity = postResponse.getEntity();
String printResult = EntityUtils.toString(postResponseEntity);

【问题讨论】:

    标签: json


    【解决方案1】:

    找到答案:只需将 toString() 添加到 info.put("japString", "よやかなゆひま".toString());。在内部,它转义了 unicode 字符。

    【讨论】:

      【解决方案2】:

      只需使用 postCard.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")) 代替 希望这会有所帮助

      【讨论】:

        猜你喜欢
        • 2018-06-16
        • 2013-02-27
        • 2021-02-19
        • 1970-01-01
        • 2016-02-17
        • 1970-01-01
        • 2021-01-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多