JSON
public static void main(String[] args) { File file=new File("/Users/litingyu/Downloads/1.txt"); try{ FileInputStream fileStrem=new FileInputStream(file); int size=fileStrem.available(); byte[] fileData=new byte[size]; fileStrem.read(fileData); fileStrem.close(); String jsonString=""; jsonString=new String(fileData,"utf-8"); typeResult(jsonString, "result"); typeResult(jsonString, "chinaresult"); } catch(IOException e){ } } public static void typeResult(String jsonString,String Key){ JSONArray jsonResult=getJSONArrayByKey(jsonString,Key); List<JSONObject> resultList=JSON.parseArray(jsonResult.toJSONString(), JSONObject.class); Iterator<JSONObject> it = resultList.iterator(); while(it.hasNext()){ JSONObject jsonJob=it.next(); System.out.println(String.valueOf(jsonJob.get("time"))+String.valueOf(jsonJob.get("status"))); } } public static JSONArray getJSONArrayByKey(String jsonString,String Key){ JSONObject jsonObj=JSON.parseObject(jsonString); JSONArray jsonResult=jsonObj.getJSONArray(Key); return jsonResult; }
{"isintl":true,"number":"YHB00010000961","chinanumber":"9740733587001","delcompany":"EMS","result":[{"time":"2016-07-01 19:07:00","status":"包裹开始清关。Package begin to customs clearance. ","place":"Chengdu"},{"time":"2016-07-01 11:29:00","status":"包裹所在航班已降落。Flight has landed. ","place":"Chengdu"},{"time":"2016-06-29 20:20:02","status":"包裹登机。航班[RU 326 / 29 RU 485 / 30 ]于[2016-06-29 08:21:24]起飞,[2016-06-30 08:21:33]到达。Item on the way to the destination country. ","place":"Amsterdam"},{"time":"2016-06-24 14:26:08","status":"包裹已经离开[{Meerbusch}]仓库运往[阿姆斯特丹]机场。","place":"Meerbusch GERMANY"},{"time":"2016-06-21 22:15:57","status":"包裹已经装箱付运。","place":"Meerbusch GERMANY"},{"time":"2016-06-20 17:02:51","status":"商品打包完毕。","place":"Meerbusch GERMANY"},{"time":"2016-06-20 16:00:35","status":"订单[10000961]分配至[Meerbusch]仓库。","place":"Meerbusch GERMANY"}],"chinaresult":[{"time":"2016-07-07 12:11:00","status":"[天津市 妥投] 投递并签收,签收人:本人收"},{"time":"2016-07-07 08:02:47","status":"[天津市] 天津市体院北投递分局安排投递(投递员姓名:155;联系电话:)"},{"time":"2016-07-07 02:11:00","status":"[天津市] 到达 天津邮区中心局 处理中心"},{"time":"2016-07-06 22:54:00","status":"[北京市] 离开北京市 发往天津市(经转)"},{"time":"2016-07-06 13:03:00","status":"[北京市] 到达中国邮政速递物流股份有限公司北京市邮件处理中心(航空)处理中心(经转)"},{"time":"2016-07-05 09:07:00","status":"[成都市] 离开成都市 发往北京市"},{"time":"2016-07-04 16:40:24","status":"[成都市] 成都市邮政速递物流有限公司国际业务分公司已收件(揽投员姓名:李翰恒,联系电话:)"}],"expressType":"EMS"}