jackson

这个写的蛮好的: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("===================================");
             }
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值