Created
October 22, 2014 13:21
-
-
Save kymmt90/bd23b5ef460ccf628453 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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