解码android上的波斯语字符

时间:2014-05-26 12:50:04

标签: php android decode

我得到一些字符(英语和波斯语)的php和解码在android上,我使用utf-8格式,但在输出显示问号字符。 这是我的代码:

    try {    
        JSONObject toSend = new JSONObject();
        toSend.put("type", "all");

       String result="";   
        JSONTransmitter transmitter = new JSONTransmitter();
      AsyncTask<JSONObject, JSONObject, JSONObject> jo=  transmitter.execute(new JSONObject[] {toSend});
     JSONObject jjjj=jo.get();

    JSONArray array=jjjj.getJSONArray("rows");
for (int i = 0; i < array.length()-1; i++) {
        JSONObject json_data = array.getJSONObject(i);
        JSONArray arr1=json_data.getJSONArray("row");
        str_url[i]=arr1.getString(0);   
        str_id[i]= URLDecoder.decode(arr1.getString(1), "UTF-8");


        Log.d("GEEEETTTT BYYYYTTTEEE", str_id[i] );
        Log.d("GEEEETTTT BYYYYTTTEEE",str_id[i]);

    }     

    } catch (JSONException e) {
        Log.e("JSONException****:::", e.getMessage());      


    } catch (InterruptedException e) {
        Log.e("InterruptedException:::", e.getMessage());
    } catch (ExecutionException e) {
        Log.e("ExecutionException:::", e.getMessage());
    } catch (UnsupportedEncodingException e) {
        Log.e("UnsupportedEncodingException:::", e.getMessage());
    } 

这是我的Log猫: Log

1 个答案:

答案 0 :(得分:0)

这是我的JSONTransmitter:

public class JSONTransmitter extends AsyncTask<JSONObject, JSONObject, JSONObject> {
String url = "my url";

@Override
protected JSONObject doInBackground(JSONObject... data) {
    JSONObject json = data[0];
    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 100000);

    JSONObject jsonResponse = null;
    HttpPost post = new HttpPost(url);
    try {
        StringEntity se = new StringEntity("json="+json.toString());
        post.addHeader("content-type", "application/x-www-form-urlencoded");
        post.setEntity(se);

        HttpResponse response;
        response = client.execute(post);
        String resFromServer = org.apache.http.util.EntityUtils.toString(response.getEntity());

        jsonResponse=new JSONObject(resFromServer);

    } catch (Exception e) { e.printStackTrace();}

    return jsonResponse;
}

}