直接看代码:
//通过put方式来创建 jsonarray
Map<String,String> t = new HashMap<String,String>();
t.put("product_id","131700" );
t.put("ordernum","0" );
t.put("personlimit","2" );
t.put("ofbiz_seckill_id","Mily46e4985biw62a88i" );
t.put("price", "10");
t.put("member_lv_ids", "1,2,3,4,5,6,7,8");
t.put("end_time", "2016-12-31 15:49:47");
t.put("nums", "10");
t.put("seckill_id", "");
t.put("name", "525367250784-S4a");
t.put("goods_id", "18682");
t.put("start_time", "2016-12-01 15:49:45");
t.put("act_open", "true");
JSONObject jsonObject = new JSONObject(t);//创建jsonObjec对象
String fileds = jsonObject.toString();//josn格式的字符串
// System.out.println(fileds);
JSONArray jsonArray = new JSONArray();
jsonArray.put(fileds);
jsonArray.put(fileds);
//
System.out.println(jsonArray);
//通过fromCollection 创建jsonArray
Map<String,String> t2 = new HashMap<String,String>();
t2.put("product_id","131700" );
t2.put("ordernum","0" );
t2.put("personlimit","2" );
t2.put("ofbiz_seckill_id","Mily46e4985biw62a88i" );
t2.put("price", "10");
t2.put("member_lv_ids", "1,2,3,4,5,6,7,8");
t2.put("end_time", "2016-12-31 15:49:47");
t2.put("nums", "10");
t2.put("seckill_id", "");
t2.put("name", "525367250784-S4a");
t2.put("goods_id", "18682");
t2.put("start_time", "2016-12-01 15:49:45");
t2.put("act_open", "true");
List<Map<String, String>> list = new ArrayList<Map<String,String>>();
list.add(t2);
list.add(t2);
JSONArray jsonArray2 = JSONArray.fromCollection(list);
System.out.println(jsonArray2);