简单说明,这里是使用Gson将json字符串转换成功我们想要的list对象
需要转换的字符串
[{"id":2303,"goodsId":3817,"goodsName":"前腿肉 鲜猪肉","goodsNum":1,"orderNumber":"WPSN350120200402102442753117000","orderSn":"WPSN350120200402102442753117001","cost":0,"price":29,"allPrice":29,"costPrice":0,"smallPic":"https://test-1259235038.cos.ap-guangzhou.myqcloud.com/user_20200401110236_800x800%E4%BA%94%E8%8A%B1%E8%82%89.jpg","specDescribe":"1斤","specKey":"20200401110427082","userId":123549}]
需要引用的jar包
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
代码操作
Gson gson = new Gson();
List<WpOrderGoods> goods = gson.fromJson(goods1,
new TypeToken<List<WpOrderGoods>>() {
}.getType());
其中,goods1 就是需要装换的字符串;WpOrderGoods实体类为字符串所对应的属性值
WpOrderGoods类
private Integer id;
private Integer goodsId;
private String goodsName;
private Integer goodsNum;
private String orderNumber;
private String orderSn;
private BigDecimal cost;
private BigDecimal price;
private BigDecimal allPrice;
private BigDecimal costPrice;
private BigDecimal discountPrice;
private String smallPic;
private String specDescribe;
private String specKey;
private Long userId;
private Byte isAppraise;
private Integer specType;
private Integer subattrId;
private Byte isReply;
private Byte isReturnApply;
private Integer goodsShipTpl;
private Date createTime;
private BigDecimal goodsPrice;
注:get,set已省略
结果:
以上就是我要分享的内容,第一次写博客有问题的地方欢迎私聊