Ho una stringa in formato JSON fatta così:
Sto cercando di ottenere due array, uno contenente tutti i "summary" e uno contenente tutti i "sections", ma non mi riesce.codice:{"routes": { "route": [ { "summary": { "leaveat": "11:58", "arriveby": "12:23", "duration": "25 mins", "transfers": 1, "fareA": "1euro", "fareC": "0.8euro" }, "sections": [ {"section1": "Station1/11:58-11:59"}, {"section2": "Station2/12:06-12:23"}, {"section3": "Station3/x"} ] }, { "summary": { "leaveat": "12:03", "arriveby": "12:43", "duration": "40 mins", "transfers": 2, "fareA": "1.4euro", "fareC": "1euro" }, "sections": [ {"section1": "Station1/12:03-12:20"}, {"section2": "Station2/12:21-12:25"}, {"section3": "Station3/12:28-12:32"}, {"section4": "Station4/x"} ] } ] } }
Sto usando la libreria JSON-lib, con questo codice dovrei avere tutti gli oggetti "route"
come faccio ora ad ottenere i due array di cui ho bisogno?codice:JSONObject json = (JSONObject) JSONSerializer.toJSON( result ); JSONArray routes = (JSONArray)json.getJSONArray("route");

Rispondi quotando