List转JsonArray和JsonObject

参考网址:https://www.cnblogs.com/zhujiabin/p/5684746.html

JSONObject  jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
for (int a=0;a<viewList.size();a++){
     JSONObject obj = new JSONObject();
     ViewBean viewBean = viewList.get(a);
     obj.put("a",viewBean.getA());
     obj.put("b",viewBean.getB());
     obj.put("c",viewBean.getC());
     obj.put("d",viewBean.getD());
     obj.put("e",viewBean.getE());
     jsonArray.put(obj);
}
jsonObject.put("array",jsonArray);
String json = java.net.URLEncoder.encode(jsonObject.toString(), "utf-8");
发布了19 篇原创文章 · 获赞 15 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/aidou1314/article/details/89005191