java中JSON串转换并获取数据

时间:2022-11-30 10:24:50

String strAllImp= " [{"id":2,"name":"还不错","count":3}]";
   
  
   JSONArray arr = new JSONArray();
   if(StringUtils.isNotEmpty(strAllImp)){
    arr = JSONArray.fromObject(strAllImp);
   }
  
     for(int i=0;i<arr.size();i++){
      JSONObject obj = arr.getJSONObject(i);
      int jsonId = obj.getInt("id");
     
       int count = obj.getInt("count");
       obj.put("count", count+1);//注意和element还有accumulate的区别
       flag = false;
       break ;  
   }