JAVA 解析 JSON
添加时间:2013-8-7 点击量:
所需包:
json-lib-2.4-jdk15.jar
commons-lang 2.5
commons-beanutils 1.8.0
commons-collections 3.2.1
commons-logging 1.1.1
ezmorph 1.0.6
JSON JSONtext :
{errorString:,orders:[{orderNo:0013036002805,status:Y,pay_time:2013-06-08 16:24:49,distribute_time:2013-07-24 11:10:24,delivery_time:2013-07-24 11:50:53,payment:0.00,receiver_name:阎兴,receiver_state:四川省,receiver_city:宜宾市,receiver_district:兴文县,receiver_address:四川省宜宾市司宿舍,receiver_zip:6440,receiver_mobile:1346451,receiver_phone:,buyer_message:,Remarks:,orderItems:[{no:1,itemNo:600000105,num:6,remark:}]},{orderNo:001307042,status:Y,pay_time:2013-07-25 14:35:34,distribute_time:2013-07-26 13:25:57,delivery_time:,payment:0.01,receiver_name:林,receiver_state:甘省,receiver_city:兰州市,receiver_district:榆中县,receiver_address:甘肃省兰市中县肃甘肃,receiver_zip:73000,receiver_mobile:138703,receiver_phone:,buyer_message:,Remarks:,orderItems:[{no:1,itemNo:67220011,num:1,remark:}]}],total_results:2}
//解析实例:
1 JSONObject ALL=JSONObject.Object(JSONtext);
2 Object errorString=ALL.getJSONArray(errorString);
3 Object total_results=ALL.getJSONArray(total_results);
4 JSONArray orders=ALL.getJSONArray(orders);
5 JSONObject order=null;
6 for(int i=0;i<orders.size();i++){
7 order=orders.getJSONObject(i);
8 Object orderid=order.getJSONObject(orderNo);
9 Object status=order.getJSONObject(status);
10 JSONArray items=order.getJSONArray(items);
11 JSONObject item=items.getJSONObject(0);
12 Object itemNo=item.getJSONObject(itemNo);
13
14 }
15
//解析封装到javabean:
WTF
读书,不要想着实用,更不要有功利心。读书只为了自身的修养。邂逅一本好书如同邂逅一位知己,邂逅一个完美之人。有时心生敬意,有时怦然心动。仿佛你心底埋藏多年的话,作者替你说了出来,你们在时光深处倾心相遇的一瞬间,情投意合,心旷神怡。