有数组的JSON字符串转list集合和对象

使用
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

json格式如下:

{
	"recordList": [{
		"fileId": 7,
		"remark": "23213",
		"inputDuration": "4",
		"timeType": "月"
	}, {
		"fileId": 4,
		"remark": "23213",
		"inputDuration": "4",
		"timeType": "小时"
	}],
	"formCreatDate": "2019年11月11日",
	"status": 2,
	"formSign": "RENEW_01",
	"jumpUrl": "http://localhost:8087/archives/html/archivesData/batchBorrow_workflow.html?id=",
	"exampleEntity": "BATCH_BORROW",
	"remark": "23213"
}

转换方法:

		JSONObject jsonObject = JSONObject.parseObject(param);
        JSONArray array = jsonObject.getJSONArray("recordList");
        List recordVOList = new ArrayList();
        for(int i = 0; i < array.size(); i++){
            JSONObject object = (JSONObject) array.get(i);     //将array中的数据进行逐条转换
            LendingRecord record = (LendingRecord) JSONObject.toJavaObject(object, LendingRecord.class);  //通过JSONObject.toBean()方法进行对象间的转换
            recordVOList.add(record);
        }
        LendingRecordApply applyVO = JSONObject.parseObject(param,LendingRecordApply.class);

你可能感兴趣的:(JSON)