当我在android中创建json时,我将阿拉伯字符放在json中,如下所示:

 HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost(url);
 JSONObject json = new JSONObject();
 try {
       json.put("jsonValue", "بسم الله ");
 } catch(Exception e) {
 }
 JSONArray postjson = new JSONArray();
 postjson.put(json);

 httppost.setHeader("json", json.toString());
 httppost.getParams().setParameter("jsonpost", postjson);

 HttpResponse response = httpclient.execute(httppost);


php代码包含charset_utf_8,但结果不正确。
php代码如下所示

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <?php

   $json = $_SERVER['HTTP_JSON'];
   var_dump($data);
   $data = json_decode($json);
   $jsonValue= $data->jsonValue;

   echo $jsonValue;
 ?>


像这样打印结果“(3E'DDG”,请问有人可以帮助吗?

最佳答案

您可以在android中使用URLEncoder,如下所示:

json.put("jsonValue",URLEncoder.encode(jsonValue, "utf-8"));


并在您的php代码中使用urldecode:

$jsonValue= urldecode($data->jsonValue);

07-24 09:19