Java对象数组与JSON相互转换

最近在做项目的时候,需要将 json对象数据存入到数据库中去…

实体类

/**
 * @ClassName: CaseModulars
 * @Author: LW
 * @Date: 2021-02-27 17:00
 **/
@Data
public class CaseModular implements Serializable {
    private static final long serialVersionUID = 812860357094906855L;
    //病例模块编号
    private  String caseModularId;

    //模块标题
    private  String title;

}
// 将存入数据库中的JSon对象解析为 Java中的 List<T> 对象数组
public List<CaseModular> getImagesExamineJsonList() {
    if (this.imagesExamineJson != null) {
    //将数据库中的json字符串转换为 List对象
        List<CaseModular> caseModularList = JSON.parseObject(this.imagesExamineJson, new TypeReference<List<CaseModular>>() {});
        this.imagesExamineJsonList = caseModularList;
    }
    return this.imagesExamineJsonList;
}

//list对象数组 转换为 json字符串
String imagesExamineJson = JSON.toJSONString(caseModularList);
Mysql数据库中存储为 varchar :

[{"caseModularId":"07e7db5910ef434f9f5697382f9f7d45080","title":"20210302"}]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值