public static void main(String args[]){
JSONObject json=new JSONObject();
JSONArray jsonList=new JSONArray();
for(int i=0;i<10;i++){
JSONObject tempJson=new JSONObject();
tempJson.put("allOrderId", "1233344"+i);
tempJson.put("product","product"+i);
tempJson.put("price", "10.0"+i);
jsonList.add(tempJson);
}
json.put("address", "广州市白云区竹料镇");
json.put("orderId", "20140304");
json.put("total","1000.1");
json.put("materialAllOrder", jsonList);
System.out.println(json.toString());
}
//输出下方json
{"address":"广州市白云区竹料镇","orderId":"20140304","total":"1000.1","materialAllOrder":[{"allOrderId":"12333440","product":"product0","price":"10.00"},{"allOrderId":"12333441","product":"product1","price":"10.01"},{"allOrderId":"12333442","product":"product2","price":"10.02"},{"allOrderId":"12333443","product":"product3","price":"10.03"},{"allOrderId":"12333444","product":"product4","price":"10.04"},{"allOrderId":"12333445","product":"product5","price":"10.05"},{"allOrderId":"12333446","product":"product6","price":"10.06"},{"allOrderId":"12333447","product":"product7","price":"10.07"},{"allOrderId":"12333448","product":"product8","price":"10.08"},{"allOrderId":"12333449","product":"product9","price":"10.09"}]}