I'm following this tutuorial here, and my JSON object is near enough the same, except I have this sort of format:
{"user":{
"SomeKeys":"SomeValues",
"SomeList":["val1","val2"]
}
}
Here is my relevant code:
Object obj = parser.parse(new FileReader("exampleJson.json"));
JSONObject jsonObject = (JSONObject) obj;
JSONObject user = (JSONObject) jsonObject.get("user");
JSONArray list = (JSONArray) user.get("SomeList");
Then my program goes off an gets the values form the keys etc. Or it would but I get a NullPointerException from eclipse. Why is this?
It should unpackage my .json file into jsonObject, unpackage the "user" key as a JSONObject user, then unpackage the "SomeList" key as a JSONArray called list. Except when it does so it must be trying to put one of val1 or val2 into a part of the JSONArray that does not exist and just points into the abyss of null. What have I done to deserve this wrong ?
How do I fix my program?