这个写的蛮好的:http://blog.csdn.net/java_huashan/article/details/46375857
更牛叉的用法:http://blog.csdn.net/sdyy321/article/details/40298081
著名json第三方库还有json-lib,gson等:http://www.open-open.com/lib/view/open1397870197828.html
jackson在网上找jar包下载时才发现以前用过这玩意(话说作为程序猿,我怎么堕落到自己去找jar包….),竟然一点印象都没有,果然写博客还是有必要的。下附自己是咋用的:
public static void jsonParse(String json) throws JsonProcessingException, IOException{
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(json);
JsonNode nodes = rootNode.path("airResultDto").path("productUnits");
for (JsonNode node : nodes) {
String price = node.path("fareInfoView").path(0).path("fare").path("salePrice").asText();
String kind = node.path("productInfo").path("productName").asText();
JsonNode msgNodes = node.path("oriDestOption").path(0).path("flights");
for (JsonNode msgNode : msgNodes) {
String flightno=msgNode.path("flightNumber").asText();
String startTime=msgNode.path("departureDateTime").asText();
String endTime=msgNode.path("arrivalDateTime").asText();
JsonNode startNode=msgNode.path("departureAirport");
String startPort=startNode.path("cityContext").asText()
+startNode.path("codeContext").asText();
JsonNode endNode=msgNode.path("arrivalAirport");
String endPort=endNode.path("cityContext").asText()
+endNode.path("codeContext").asText();
System.out.println(kind+":"+price);
System.out.println(flightno);
System.out.println(startTime);
System.out.println(endTime);
System.out.println(startPort);
System.out.println(endPort);
System.out.println("===================================");
}
}
}