2012-02-13 83 views
1

我尝试通过json发送日语信件,但是,返回的json值是"jspString":"???????"。我究竟做错了什么?谢谢!通过JSON发送日语字符

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); 

回答

1

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

0

只是使用postCard.setEntity(新UrlEncodedFormEntity(namevaluepairs中, “UTF-8”)),而不是 希望这将有助于

0

我也遇到了这个问题。

$ json -n -f messages/jp.json 
json: error: "messages/jp.json" is not JSON: Bad string at line 194, column 38: 
     "Statement from HQ:": "本部からの声明:", 
    .....................................^ 

我最初以为是坏的Unicode编码,所以我translated the characters to escaped unicode

不过,我替换值后跑了验证,并发现了一个糟糕的“隐形”的JSON键结束(后逗号)。

我能够通过删除行末尾的无效字符(额外的“空格”)来解决这个问题。

我找到了一篇相关文章,但接受的答案指出编码字符应该在文件的开头,所以这不完全是我打算的问题,我不相信。 Clean source code files of invisible characters