-2

I am trying to parse json values into my Android application and put the result in a lisview. There is my JSON result:

[
{"dateticket": "12/02/2015",
"description": "kkkkkk",
"etat": "suivi",
"idticket": 32,
"nomfichier": "contrat",
"objet": "contrat",
"priorite": "first"},
{"dateticket": null,
"description": null,
"etat": "en cours",
"idticket": 98,
"nomfichier": "lotfi",
"objet": "contrat",
"priorite": "normale"},
{
"dateticket": null,
"description": null,
"etat": "en cours",
"idticket": 99,
"nomfichier": "lotfi",
"objet": "contrat",
"priorite": "normale"},
]

Thanks in Advance

2
  • Can you explain what is the problem?? you can try using 'JsonObject' and 'JsonArray' Commented May 29, 2015 at 14:05
  • possible duplicate of Convert Json Array to normal Java Array Commented May 29, 2015 at 14:05

3 Answers 3

4

Maybe like this

Make necessary changes.

private void OpenparseJson(String stringJson) {
    try {
        JSONArray jArray = new JSONArray(stringJson);
        JSONObject jObject = null;
        for (int i = 0; i < jArray.length(); i++) {
            jObject = jArray.getJSONObject(i);
            String s1 = jObject.getString("dateticket");
            String s2 = jObject.getString("description");
            String s3 = jObject.getString("etat");
            String s4 = jObject.getString("idticket");
            String s5 = jObject.getString("nomfichier");
            String s6 = jObject.getString("objet");
            String s7 = jObject.getString("priorite");
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

create jsonarray and then iterate each jsonobject inside this jsonarray into jsonobject object and the getstring using key of each

JsonArray array=new JsonArray(<responsestring>);
for(int i=0;i<array.length();i++)
{
 JsonObject json=array.getJsonObject(i);
 String dateticket= json.getString("dateticket");
 //......etc
}

Comments

0

There's a simple tutorial here that you can follow

Also consider using GSON library to parse JSON data in Java. It removes the need to have loops/if statements etc. whilst parsing. More info on that here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.