当我在 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);
关于php - 我如何将 json 中的阿拉伯字符从 android 发送到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36860414/