JSONArray转String,String转JSONArray
业务需求
前端传来参数格式,重点是附件
附件传来是数组格式,但是数据库的content是text类型,所以存之前要转一下
"dealFields": [
{
"fieldName": "处理日期",
"content": "2020/05/24"
},
{
"fieldName": "附件",
"content": [
{
"fileId": 9313,
"fileName": "da3150d6f8e80cfdce58dd5b171695db.jpeg",
"filePath": "M00/00/64/epDdgV9eyV2ASME1AA4N08g9oSU83.jpeg"
},
{
"fileId": 9314,
"fileName": "4cd1b55831d7605dd165762be657569f.jpg",
"filePath": "M00/00/64/epDdgV9eyV2AAd65AAB98PEeCc0597.jpg"
}
]
}
]
}
数组转字符串
map.put(“content”,JSONArray.toJSONString(dealField.getJSONArray(“content”)));
此时存储再数据库表的格式为
[{“fileId”:9313,“fileName”:“da3150d6f8e80cfdce58dd5b171695db.jpeg”,“filePath”:“M00/00/64/epDdgV9eyV2ASME1AA4N08g9oSU83.jpeg”},{“fileId”:9314,“fileName”:“4cd1b55831d7605dd165762be657569f.jpg”,“filePath”:“M00/00/64/epDdgV9eyV2AAd65AAB98PEeCc0597.jpg”}]
返回给前端的时候,需要将字符串在转给JSON数组
examineContent.put(“content”,JSONArray.parseArray(examineContent.get(“content”).toString(), FileInfo.class));