Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve JSON data inside an JSON object?
    primarykey
    data
    text
    <p>I have a JSON Object that looks like this : </p> <pre><code>"TripList":{ "noNamespaceSchemaLocation":"http://api.vasttrafik.se/v1/hafasRestTrip.xsd", "servertime":"11:27", "serverdate":"2013-04-02", "Trip":[{ "Leg":{ "name":"Spårvagn 3", "type":"TRAM", "id":"9015014500300079", "direction":"Kålltorp", "fgColor":"#004b85", "bgColor":"#ffffff", "stroke":"Solid", "accessibility":"wheelChair", "Origin":{ "name":"Brunnsparken, Göteborg", "type":"ST", "id":"9022014001760004", "routeIdx":"19", "time":"11:27", "date":"2013-04-02", "track":"D ", "rtTime":"11:31", "rtDate":"2013-04-02", "$":"\n" } </code></pre> <p>to get the name inside the Leg object is working fine. But if I wanna get thetime inside the Origin object how do I do that?</p> <p>My code is like this so far:</p> <pre><code> JSONParser parser = new JSONParser(); Object obj = parser.parse(Planner.getPlanner().getJsonDataForTrip(Planner.getPlanner().getStartLocationID(), Planner.getPlanner().getDestinationID())); JSONObject topObject = (JSONObject) obj; JSONObject locationList = (JSONObject) topObject.get("TripList"); JSONArray array = (JSONArray) locationList.get("Trip"); Iterator&lt;JSONObject&gt; iterator = array.iterator(); while (iterator.hasNext()) { JSONObject jsonObj = iterator.next(); jsonObj = (JSONObject) jsonObj.get("Leg"); String line = (String) jsonObj.get("name"); Planner.getPlanner().setLines(line); System.out.println(jsonObj.get("Origin")); Long time = (Long) jsonObj.get("time"); String track =(String) jsonObj.get("track"); System.out.println(line); System.out.println(time); System.out.println(track); } </code></pre> <p>}</p> <pre><code>And in the console it say like this : </code></pre> <blockquote> <p>{"routeIdx":"19","id":"9022014001760004","rtDate":"20130402","time":"15:02","$":"\n","name:"Brunnsparken, Göteborg","track":"D ","rtTime":"15:06","date":"2013-04-02","type":"ST"}</p> <p>Spårvagn 3</p> <p>null</p> <p>null</p> </blockquote> <p>So basiclly i am getting the name Spårvang 3 already. But I wanna get the time.</p> <p>so the time that I am trying to get out by using <code>jsonObj.get("time");</code> is giving a <code>null</code> value.</p> <p>Whats the problem and how can I get the time from the object "Origin"??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload