Skip to content

Instantly share code, notes, and snippets.

@Rubatharisan
Created April 24, 2014 09:43
Show Gist options
  • Save Rubatharisan/11248506 to your computer and use it in GitHub Desktop.
Save Rubatharisan/11248506 to your computer and use it in GitHub Desktop.
JsonParserDemo jsonParserDemo =
new JsonParserDemo("/Users/rubas/item.json", true);
try(JsonReader jsonReader = jsonParserDemo.getJsonReader()){
Gson myGson = new Gson();
JsonParser jsonParser = new JsonParser();
JsonArray userArray = jsonParser.parse(jsonReader).getAsJsonArray();
ArrayList<Object> Items = new ArrayList<>();
for ( JsonElement aUser : userArray ){
Items aItem = myGson.fromJson(aUser, Items.class);
Items.add(aItem);
}
for ( Object item : Items){
System.out.println(((Items) item).getName() + "\n");
System.out.println(((Items) item).getId() + "\n");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment