I have this JSON:
request_time: "2018-03-13T00:59:44+00:00",
stops: [
{
atcocode: "370023715",
mode: "bus",
name: "AG1",
stop_name: "AG1",
smscode: "37023715",
bearing: "N",
locality: "Sheffield Centre",
indicator: "AG1",
longitude: -1.46616,
latitude: 53.38248,
distance: 57
},
{
atcocode: "370027281",
mode: "bus",
name: "AG12",
stop_name: "AG12",
smscode: "37027281",
bearing: "N",
locality: "Sheffield Centre",
indicator: "AG12",
longitude: -1.46583,
latitude: 53.38228,
distance: 77
}
]
}
I would like to retrieve and store each locality and atocode within this sub tree, in an array. I currently have this java code, but it only displays everything within the sub tree :
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(json);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
if (element.isJsonObject()){
JsonObject bus = element.getAsJsonObject();
JsonArray array = bus.getAsJsonArray("stops");
for (int i = 0; i < array.size(); i++){
out.println(array.get(i));
}