Hi all I have been trying to parse the above JSON into a java program and store it into an object... (Don't have a specific structure at the moment, as long as I can get the data from the object.)
Have been trying to use GSON but I can't seem to get it right..
String inputLine="";
HttpClient httpclient= new DefaultHttpClient();
HttpGet method = new HttpGet("http://localhost:3000/specs/215/errors.js");
HttpResponse response =httpclient.execute(method);
BufferedReader in = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()));
inputLine = in.readLine();
System.out.println(inputLine);
in.close();
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonArray array = parser.parse(inputLine).getAsJsonArray();
for(int i=0; i < array.size(); i++) {
Errors e = gson.fromJson(array.get(0), Errors.class);
System.out.println(e.error.getReason());
}
and the error i get is:
Exception in thread "main" java.lang.IllegalStateException: This is not a JSON Array.
at com.google.gson.JsonElement.getAsJsonArray(JsonElement.java:99)
at test.Getter.main(Getter.java:37)
Anyone please point me in the right direction? Thanks.