Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android/java-从服务器接收utf-8字符串(json)_Android_Android Activity - Fatal编程技术网

android/java-从服务器接收utf-8字符串(json)

android/java-从服务器接收utf-8字符串(json),android,android-activity,Android,Android Activity,我试图通过json编码函数从php脚本接收utf-8格式的字符串。例如,字符串为:\u00e9\u00e5\u00f1\u00e9。我认为php脚本做得很好,它看起来是正常的utf-8 android将此字符串显示为奇怪的字母。我试图转换字符串,但无效。字符串是name-希伯来语中的一个变量 JSONObject json = new JSONObject(data[x]); name = json.getString("name"); weight = json.getString(

我试图通过json编码函数从php脚本接收utf-8格式的字符串。例如,字符串为:\u00e9\u00e5\u00f1\u00e9。我认为php脚本做得很好,它看起来是正常的utf-8

android将此字符串显示为奇怪的字母。我试图转换字符串,但无效。字符串是name-希伯来语中的一个变量

    JSONObject json = new JSONObject(data[x]);
name = json.getString("name");
weight  = json.getString("weight");
height  = json.getString("height"); 
target  = json.getString("target");
calories = json.getDouble("calories");
bmi = json.getDouble("bmi");
bmr = json.getDouble("bmr");

String name2 = null;

  byte[] bytes = name.getBytes();
 name2 = new String(bytes, "UTF-8");

    Toast.makeText(getApplicationContext(),"n" + name2, Toast.LENGTH_SHORT).show();
php脚本:

     // loading values from database...

     $name = utf8_encode($name);
    $data = array(name => "$name",pass => "$pass");
    $length=count($array);

    echo json_encode($data); 
我也试过:

String name2 = null;
    byte[] bute = null;
    bute = name.getBytes();
    try {
         name2= new String(bute, "UTF-8");


    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

你能显示服务器端代码吗?@ItzikSamara我编辑了这个答案@ItzikSamara,我试过。。。还是一样的问题。。。toda al Aezrai如果你不在服务器中编码PHP,你会得到什么?>