panzerfaustnl
Nieuwe gebruiker
- Lid geworden
- 26 feb 2015
- Berichten
- 3
Hallo allemaal,
Ik zit al een flinke avond te knoeien met een leuke opdracht,
Ik heb een JSONObject met de volgende vulling:
Maar op coordinates en lowestFare, loopt de volgende code niet:
iemand een idee waarom dit niet loopt? Ik heb al allerlei dingen geprobeerd met JSONArray's etc. Maar echt verder kom ik niet.
Ik zit al een flinke avond te knoeien met een leuke opdracht,
Ik heb een JSONObject met de volgende vulling:
Code:
{"destinations":[{"origin":"AMS","destination":{"code":"AAL","name":"Aalborg","description":"Aalborg (AAL)","country":"DK","continent":"EUR","coordinates":{"lat":57.08944,"lon":9.84889}},"lowestFare":{"value":149.0,"currency":"EUR"}}
Maar op coordinates en lowestFare, loopt de volgende code niet:
Code:
public void getDestinations() {
RestTemplate restTemplate = new RestTemplate();
List<KLM> klmApp = new ListImpl();
JSONObject jsonResult = null;
JSONArray arrayResult = null;
ArrayList<String> listObjects = null;
try {
HttpEntity<?> responseEntity = restTemplate.getForEntity(url, String.class);
System.out.println(responseEntity.getBody());
JSONObject json = (JSONObject) JSONValue.parse(responseEntity.getBody().toString());
List<JSONObject> list = (List<JSONObject>) json.get("destinations");
if (list != null)
{
for (JSONObject s : list)
{
System.out.println(s.toJSONString());
JSONParser parser = new JSONParser();
try
{
Object obj = parser.parse(s.toJSONString());
JSONObject jsonObject = (JSONObject)obj;
HashMap<String,String> destination = (HashMap<String,String>)jsonObject.get("destination");
System.out.println("==========================");
System.out.println(destination.get("continent"));
System.out.println(destination.get("country"));
System.out.println(destination.get("code"));
System.out.println(destination.get("name"));
System.out.println(destination.get("coordinates"));
System.out.println(destination.get("description"));
System.out.println(destination.get("lowestFare"));
System.out.println(destination.get("currency"));
System.out.println(destination.get("value"));
System.out.println("==========================");
}
catch(Exception ex)
{
ex.printStackTrace();
System.out.println("==========================");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
iemand een idee waarom dit niet loopt? Ik heb al allerlei dingen geprobeerd met JSONArray's etc. Maar echt verder kom ik niet.