json里面包含json数组

首先需要这个依赖

<dependency>
    <groupId>net.sf.json-lib</groupId>
    <artifactId>json-lib</artifactId>
    <version>2.4</version>
    <classifier>jdk15</classifier>
</dependency>

然后需要引入两个包

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

下面就是代码例子

JSONObject jsonParam = new JSONObject();
JSONArray array
= new JSONArray(); for(PPayOrderBill bill:pPayOrderBillList){ jsonParam.put("receivableId",bill.getBillId()); array.add(jsonParam); } JSONObject object = new JSONObject(); if(pPayOrderResult != null && params != null) { object.put("paymentId",pPayOrderResult.getGuid()); object.put("houseId", pPayOrderResult.getHourceGuid()); object.put("paymentList", array); }
原文地址:https://www.cnblogs.com/lx-1024/p/8011538.html