OckhamsRazor
OckhamsRazor

Reputation: 4906

Sending japanese characters over JSON

I tried sending japanese letters via json, however, the json value returned is "japaneseString":"???????". What am I doing wrong? Thanks!

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

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

Upvotes: 1

Views: 7043

Answers (2)

OckhamsRazor
OckhamsRazor

Reputation: 4906

Found the answer: just add toString() to info.put("japaneseString", "よやかなゆひま".toString());. Internally, it escapes the unicode characters.

Upvotes: 2

Ezeki
Ezeki

Reputation: 149

just use postCard.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")) instead hope this will help

Upvotes: -1

Related Questions