【发布时间】:2018-01-27 09:35:40
【问题描述】:
我正在使用以下方法将数据从 android 应用程序发送到 php 脚本:
JSONObject jsonObject= new JSONObject();
try {
jsonObject.put("name", "name ąęś");
jsonObject.put("address", "address żżóóó");
jsonObject.put("title", "title ćććżżżóóó");
} catch (JSONException e) {
e.printStackTrace();
}zamiast
JSONParser jsonParser = new JSONParser();
String url = "http://www.serwer.com/script.php";
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("post", jsonObject.toString()));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url, "POST", params);
在 php 脚本站点中,我收到这样的数据:
if(isset($_POST['post']))
{
$post_utf8 = htmlentities($_POST['post'],ENT_QUOTES, "UTF-8");
$postX = htmlspecialchars_decode($post_utf8);
$post_x = json_decode($postX, true);
echo $_POST['post']; //--> problem with utf8 , "?" instead polish characters
echo $post_x['name']; //--> problem with utf8 , "?" instead polish characters
echo "ąęź"; // --> everything OK, I can see polish characters
}
我总能看到“?”而不是波兰语字符。 使用 echo "ąźć" 我可以看到波兰语字符。 这就是 POST 方法的问题。 我已经检查了很多东西,但不幸的是我直到现在都没有找到解决方案。
【问题讨论】: