2012-02-13 44 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