代码如下:
public static void main(String[] args) {
setMapToJSON();
}
public static void setMapToJSON() {
HashMap<String, Object> root = new HashMap<String, Object>();
root.put("errorCode", 0);
root.put("errorMsg", "调用接口成功");
List<Map<String, String>> dataArr = new ArrayList<Map<String, String>>();
Map<String, String> userhelei = new HashMap<String, String>();
userhelei.put("userName", "贺雷");
userhelei.put("position", "技术网站负责人");
userhelei.put("webAddres", "www.ithelei.com");
Map<String, String> ithelei = new HashMap<String, String>();
ithelei.put("userName", "老大");
ithelei.put("position", "信融集团");
ithelei.put("webAddres", "www.wayboo.com");
dataArr.add(ithelei);
dataArr.add(userhelei);
root.put("data", dataArr);
System.out.println(new JSONObject().toJSONString(root));
}
- 邮箱 :ithelei@sina.cn
- Good Luck!