Java对象与JSON互转

2022-12-02  本文已影响0人  AC编程

一、对象与JSON互转

OrderCmd orderCmd = new OrderCmd();

//对象转JSOn
String orderJson = JSON.toJSONString(orderCmd);

//JSON转对象
OrderCmd orderCmd = JSONObject.parseObject(orderJson, OrderCmd.class);

二、集合与JSON互转

//集合转JSON
String attachmentsJSON = JSON.toJSONString(vo.getAttachmentList());

//JSON转集合
List<MessageAttachment> attachmentList = JSONObject.parseArray(attachmentsJSON, MessageAttachment.class);

上一篇下一篇

猜你喜欢

热点阅读