关于json集合的问题
我想把 "expected_revenue": "100~120", "fight_power": "120" 循环 添加到 数组里该怎么实现
ArrayList<CustomerTank> customerTanks = tankMapper.selectCustomerTank(user.getId());
JSONArray array= JSONArray.parseArray(JSON.toJSONString(customerTanks));
JSONObject json = new JSONObject();
json.put("fight_power","120");
json.put("expected_revenue","100~120");
return ResultVM.ok("获取用户坦克列表成功",array);
不知道你用的哪个json库大体是这样
ArrayList<CustomerTank> customerTanks = tankMapper.selectCustomerTank(user.getId());
JSONArray array= JSONArray.parseArray(JSON.toJSONString(customerTanks));
JSONObject json_data = new JSONObject();
// data 内容为json数组
JSONArray jsonArray = new JSONArray();
json_data.put("data",jsonArray);
for (int i=0;i<100;i++){
json.put("fight_power","120");
json.put("expected_revenue","100~120");
//"fight_power" 为data数组的元素
jsonArray.add(json);
}
array.add(json_data);