0

I jave a JSONArray "appelliLista" that get recognized as JSONObject. So i cant loop to retrieve data for each record.

                   //Recovering data object 
                    JSONObject obj = new JSONObject(response);
                    JSONObject disponibiliì = obj.getJSONObject("result");

                    JSONArray lista = disponibiliì.getJSONArray("appelliLista"); //not working
                    JSONObject  lista2 = disponibiliì.getJSONObject("appelliLista"); //working in the wrong way no error but just cant loop

JSON RESPONSE

`

{
"service": "appelliLista",
"status-code": 200,
"status-description": "success",
"time-spent": 0.116739,
"server-time": "07/05/2019-04:03:57pm",
"result": {
"appelliLista": {
1: {
"Attivita didattica": "SISTEMI OPERATIVI",
"Appello": "22/05/2019",
"Iscrizione": "07/05/201920/05/2019",
"Descrizione": "SISTEMI OPERATIVI",
"Sessioni": "2018/2019",
"link": "APP_ID=62&CDS_ESA_ID=10047&ATT_DID_ESA_ID=5868&ADSCE_ID=20148812&AA_OFF_ID=2014&CDS_ID=10047&PDS_ID=9999&AA_ORD_ID=2013&ISCR_APERTA=1&TIPO_ATTIVITA=1&TIPO_APP_COD=0"
}
}
}
}

`

8
  • check your api/web service Commented May 8, 2019 at 7:16
  • Your json array is wrong see in jsonlint.com and validate json Commented May 8, 2019 at 7:17
  • according to jsonResponse there is no JSONArray, so the code is right. You need to check up with your webservice. Commented May 8, 2019 at 7:17
  • its ok, appelliLista is an object, not array: "appelliLista": { - note it starts with { - for more see en.wikipedia.org/wiki/JSON#Data_types_and_syntax Commented May 8, 2019 at 7:18
  • can u show how should be the right format? Commented May 8, 2019 at 7:21

2 Answers 2

2

Json array format is

"appelliLista":[
  {....},
  {....}
]

your json element appelliLista is a json object so cannot parse to array

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your JSON object is like below, you can simply iterate over it this way:

        var object = {
            "service": "appelliLista",
                "status-code": 200,
                    "status-description": "success",
                        "time-spent": 0.116739,
                            "server-time": "07/05/2019-04:03:57pm",
                                "result": {
                                            "appelliLista": {
                                                1: {
                                                    "Attivita didattica": "SISTEMI OPERATIVI",
                                                        "Appello": "22/05/2019",
                                                            "Iscrizione": "07/05/201920/05/2019",
                                                                "Descrizione": "SISTEMI OPERATIVI",
                                                                    "Sessioni": "2018/2019",
                                                                        "link": "APP_ID=62&CDS_ESA_ID=10047&ATT_DID_ESA_ID=5868&ADSCE_ID=20148812&AA_OFF_ID=2014&CDS_ID=10047&PDS_ID=9999&AA_ORD_ID=2013&ISCR_APERTA=1&TIPO_ATTIVITA=1&TIPO_APP_COD=0"
                                                }
                                            }
            }
        }




        for (key in object) {
            console.log(key + " : " + object[key]);
        }

2 Comments

the language is java not javascript. can you show me how to iterate in java?
I see, you check this link, maybe it help: stackoverflow.com/questions/9151619/…

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.