import java.util.Date;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.commons.utils.DateUtil;
public class TestJson2 {
public static void main(String[] args) {
Date dateStart=new Date();
String dateStartFormat="";
dateStartFormat = DateUtil.format(dateStart, "yyyy-MM-dd")+" 00:00:00";
Date dateEnd=new Date();
String dateEndFormat="";
dateEndFormat = DateUtil.format(dateEnd, "yyyy-MM-dd")+" 23:59:59";
JSONObject jsonObject = new JSONObject();
jsonObject.put("TABLE", "POS_TRANS_AMT_DTL");
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("DEVCODE","123");
jsonObject1.put("TRANSTIME","GE "+dateStartFormat+"$LE "+dateEndFormat);
jsonObject.put("CONDITION_LIST", jsonObject1);
JSONArray jsonArray = new JSONArray();
jsonArray.add(0, "MERCHNAME");
jsonArray.add(1, "MERCHCODE");
jsonArray.add(2, "DEVCODE");
jsonArray.add(3, "TRANSTIME");
jsonArray.add(4, "TRANSAMT");
jsonArray.add(5, "TRANSTYPE");
jsonArray.add(6, "TRANSSTATUS");
jsonObject.put("RESPONSE_LIST", jsonArray);
System.out.println(jsonObject.toJSONString());
}
}
运行结果:{"TABLE":"POS_TRANS_AMT_DTL","CONDITION_LIST":
{"DEVCODE":"123","TRANSTIME":"GE 2017-09-11 00:00:00$LE 2017-09-11 23:59:59"},
"RESPONSE_LIST":["MERCHNAME","MERCHCODE","DEVCODE","TRANSTIME","TRANSAMT","TRANSTYPE","TRANSSTATUS"]
}