先把ArrayList转化为Json格式
JSONArray json = new JSONArray();
for (int i = 0; i < cartinfo.size(); i++) {
JSONObject jo = new JSONObject();
try {
jo.put("shopid", cartinfo.get(i).getShopid());
jo.put("gounum", cartinfo.get(i).getGounum());
json.put(jo);
} catch (JSONException e) {
e.printStackTrace();
}
}
把json转成url编码
String encode = URLEncoder.encode(json.toString());
payCode.setCartinfo(encode);
本文介绍了一种将ArrayList集合转换为JSON格式的方法,并进一步将其转换为URL编码字符串的过程。通过示例代码展示了如何利用Java的JSONObject和JSONArray来实现这一转换。
3223

被折叠的 条评论
为什么被折叠?



