600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > json字符串转换成list对象

json字符串转换成list对象

时间:2023-10-18 00:16:12

相关推荐

json字符串转换成list对象

简单说明,这里是使用Gson将json字符串转换成功我们想要的list对象

需要转换的字符串

[{"id":2303,"goodsId":3817,"goodsName":"前腿肉 鲜猪肉","goodsNum":1,"orderNumber":"WPSN35012002102442753117000","orderSn":"WPSN35012002102442753117001","cost":0,"price":29,"allPrice":29,"costPrice":0,"smallPic":"https://test-1259235038.cos.ap-/user_2001110236_800x800%E4%BA%94%E8%8A%B1%E8%82%89.jpg","specDescribe":"1斤","specKey":"2001110427082","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已省略

结果:

以上就是我要分享的内容,第一次写博客有问题的地方欢迎私聊

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。