JSON和List相互转化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_28729797/article/details/80307056

List<Goods> goodsList = new ArrayList<>();

goodsList.add(good);

生成JSONArray

JSONArray array = JSONArray.fromObject(goodsList);

params.put("goodsList", array.toString());

解析

List<Goods> goodsList = new ArrayList<>();

JSONArray jsonArray = JSONArray.fromObject(params.get("goodsList"));

goodsList = JSONArray.toList(jsonArray,Goods.class);//这里的tClass<T> 

猜你喜欢

转载自blog.csdn.net/sinat_28729797/article/details/80307056