简体   繁体   中英

android org.json.JSONException

Hello I have an error with my code which tells me org.json.JSONException end of input at character 0 of when I try to recover my json on the printers, normally this error occurs that its returns an empty string but I do not see Not what ...

Here is my code:

public class MaterielAssocie extends Activity {
private ListView lv;
public static etablissement etabSELECT;
private ProgressDialog progressDialog;
public static ArrayList<imprimante>detail = new ArrayList<>();
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.materiel_associe);
    lv = (ListView) findViewById(R.id.listViewMa);
    chargerJeuDessaie();
    rafraichirListView();
}

private void chargerJeuDessaie()
{
    progressDialog = progressDialog.show(this,"Gestion des services associés","Telechargement en cours");
    MonAsyncTaskHttp monAsyncTaskHttp = new MonAsyncTaskHttp() {

        @Override
        protected void onPostExecute(Object o) {
            super.onPostExecute(o);
            MaterielAssocie.detail.clear();
            try {
                JSONArray jsonArray = new JSONArray(o.toString());
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    imprimante imp = imprimante.factoryImp(jsonObject);
                    MaterielAssocie.detail.add(imp);

                    rafraichirListView();


                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            progressDialog.dismiss();
        }
    };
    monAsyncTaskHttp.execute("requete=getLesImprimantes=" + search_ville.etabSELECT.getId());
}

public void rafraichirListView() {
    ArrayAdapter<imprimante> imprimanteadapter = new ArrayAdapter<imprimante>(MaterielAssocie.this, android.R.layout.simple_list_item_1, detail);
    lv.setAdapter(imprimanteadapter);
}

here is my code of my page printer :

public class imprimante extends Activity {
    private int id_imprimante;
    private String marque_imprimante;
    private String emplacement;
    private int ref_etab;



 public imprimante(int id_imprimante, String marque_imprimante, String emplacement, int ref_etab) {
    this.id_imprimante = id_imprimante;
    this.marque_imprimante = marque_imprimante;
    this.emplacement = emplacement;
    this.ref_etab = ref_etab;
}

public int getId_imprimante() {
    return id_imprimante;
}

public void setId_imprimante(int id_imprimante) {
    this.id_imprimante = id_imprimante;
}

public String getMarque_imprimante() {
    return marque_imprimante;
}

public void setMarque_imprimante(String marque_imprimante) {
    this.marque_imprimante = marque_imprimante;
}

public String getEmplacement() {
    return emplacement;
}

public void setEmplacement(String emplacement) {
    this.emplacement = emplacement;
}

public int getRef_etab() {
    return ref_etab;
}

public void setRef_etab(int ref_etab) {
    this.ref_etab = ref_etab;
}
public String toString() {
    String lib = ""+ marque_imprimante +"  "+ emplacement +"";
    return lib;
}

public static imprimante factoryImp(JSONObject jo)
{
    imprimante imp = null;
    try {
        int id_imprimante = jo.getInt("id_imprimante");
        String marque_imprimante = jo.getString("marque_imprimante");
        String emplacement = jo.getString("emplacement");
        int ref_etab = jo.getInt("ref_etab");




        imp = new imprimante(id_imprimante,marque_imprimante,emplacement,ref_etab);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return imp;
}
}

If someone sees the error I do not see thank you

errors :

     W/System.err: org.json.JSONException: End of input at character 0 of 
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at org.json.JSONTokener.nextValue(JSONTokener.java:97)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at org.json.JSONArray.<init>(JSONArray.java:87)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at org.json.JSONArray.<init>(JSONArray.java:103)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at ddec.applicationddec.MaterielAssocie$1.onPostExecute(MaterielAssocie.java:43)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at 

android.os.AsyncTask.finish(AsyncTask.java:631)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at android.os.AsyncTask.access$600(AsyncTask.java:177)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)

JSON String

{
"type": "object",
"properties": {
    "id_imprimante": {
        "type": "int"
    },
    "marque_imprimante": {
        "type": "String"
    },
    "emplacement": {
        "type": "String"
    },
    "ref_etab": {
        "type": "int"
    },
  }
}

请把您的json字符串放在这里,并检查是否有效

The JSON string you provided is invalid, you have an extra comma at the end.

"ref_etab": { "type": "int" }, should be "ref_etab": { "type": "int" }

There is a comma de mas, check the format of your JSON 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM