Android · 2013/02/25

android发送/接收Json包含中文的处理

即在发送的时候用utf-8编码,接收的时候用utf-8解码即可!

HttpPost httpPost = new HttpPost(url);

StringEntity se = new StringEntity(jsonObject.toString(), “UTF-8”);
httpPost.setEntity(se);
se.setContentType(“application/json”);

HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);
String retSrc = EntityUtils.toString(httpResponse.getEntity(), “UTF-8”);
JSONObject result = new JSONObject( retSrc);