Java对象与JSON互转

一、对象与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 attachmentList = JSONObject.parseArray(attachmentsJSON, MessageAttachment.class);

你可能感兴趣的:(Java对象与JSON互转)