关于json格式存储数据库成bean对象list,取出来再次转换成json格式

 
 
网上很多list转JsonArray,在实际中用不了,。

private List<WmCheckListBean> checkListBean=new ArrayList<>();

JSONArray arry= new JSONArray();

for ( int a= 0;a< checkListBean.size();a++){
JSONObject jsonObject= new JSONObject();
try {
jsonObject.put( "id", checkListBean.get(a).getCheckId());
jsonObject.put( "name", checkListBean.get(a).getCheckName());
jsonObject.put( "parentId", checkListBean.get(a).getParentId());
jsonObject.put( "type", checkListBean.get(a).getType()); }
  catch (JSONException e) {
e.printStackTrace();
 }
arry.put(jsonObject);
}
原创文章 19 获赞 4 访问量 2万+

猜你喜欢

转载自blog.csdn.net/whyareusomw/article/details/78393775