後臺複雜json格式拼寫方法
阿新 • • 發佈:2018-12-18
JSONObject jsonObject = new JSONObject(); List<JSONObject> jsonList = new ArrayList<>(); for (THarvestDatasource tHarvestDatasource : list) { JSONObject jsonObject2 = new JSONObject(); jsonObject2.element("dataPath",tHarvestDatasource.getDataPath()); jsonObject2.element("datasourceName",tHarvestDatasource.getDatasourceName()); jsonList.add(jsonObject2); } jsonObject.element("data",jsonList); { "data": [ { "dataPath": "cd669a58f7bb454eb970a3403b01c39a", "datasourceName": "採集RELA" }, { "dataPath": "f8d886a810f440e398eaa340eff717b0", "datasourceName": "長生人壽資料標準資料來源" }, { "dataPath": "be32616ebbbb43c5a6fae9aa1d927cb5", "datasourceName": "資料標準採集資料來源1008" } ]