标签:string ring put util rgs tostring map valueof void
net.sf.json - JSONArray.fromObject
package com.ikoo; import java.util.ArrayList; import java.util.HashMap; import net.sf.json.JSONArray; public class Test { public static void main(String[] args) { ArrayList<HashMap<String, String>> list = new ArrayList<>(); for (int i = 0; i < 3; i++) { HashMap<String, String> map = new HashMap<>(); map.put("num", String.valueOf(i * 10)); list.add(map); } System.out.println(list);// [{num=0}, {num=10}, {num=20}] JSONArray jsonArray = JSONArray.fromObject(list); System.out.println(jsonArray);// [{"num":"0"},{"num":"10"},{"num":"20"}] String data = "{\"success\":true,\"nums\":" + jsonArray.toString() + "}"; System.out.println(data);// {"success":true,"nums":[{"num":"0"},{"num":"10"},{"num":"20"}]} } }
将 jsonArray 再自定义组装的 json
{ "success":true, "nums":[ { "num": "0" }, { "num": "10" }, { "num": "20" } ] }
net.sf.json - JSONArray.fromObject
标签:string ring put util rgs tostring map valueof void
原文地址:http://www.cnblogs.com/ikoo4396/p/7339868.html