Java中 List 和 JSON字符串之间的相互转换

List 转 JSON 字符串

 Map<String,String> map = new HashMap<>();
 map.put("name","szy");
 map.put("num",2);
 list.add(map);
 String inventoryResultStr = JSON.toJSON(list).toString();

JSON字符串转List

   

List inventoryResultList = JSONObject.parseArray(inventoryResult);
for(Integer i=0;i<inventoryResultList.size();i++){
     JSONObject jsonObject = (JSONObject) inventoryResultList.get(i);
     String name =jsonObject.getString("name");
}

猜你喜欢

转载自blog.csdn.net/xxs18326183038/article/details/86593719