Skip to content

Instantly share code, notes, and snippets.

@kymmt90
Created October 22, 2014 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kymmt90/bd23b5ef460ccf628453 to your computer and use it in GitHub Desktop.
Save kymmt90/bd23b5ef460ccf628453 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.IOException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Jackson {
public static void main(String[] args) {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(new File("test.json"));
String member_name = root.get("member").get(0).get("name").asText();
System.out.println(member_name);
int age = root.get("member").get(3).get("age").asInt();
System.out.println(age);
for (JsonNode n : root.get("album")) {
String album_name = n.get("name").asText();
int year = n.get("year").asInt();
String month = n.get("month").asText();
int day = n.get("year").asInt();
System.out.println(album_name + ": " + day + " " + month + " " + year);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment