0

I'm trying to receive a string in utf-8 from php script by json encode function. the string is for example: \u00e9\u00e5\u00f1\u00e9 . ( I think that the php script did his work good, it looks normal utf-8)

android shows this string as strange letters. I have tried to convert the string but it didn't work. the string is "name" - it's a variable in Hebrew.

    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 script:

     // loading values from database...

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

    echo json_encode($data); 

I tried also:

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();
    }
May
  • 47
  • 7

0 Answers0