把ArrayList轉化爲Json格式,在用url編碼

先把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);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章