代碼如下:
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", "調(diào)用接口成功");
List<Map<String, String>> dataArr = new ArrayList<Map<String, String>>();
Map<String, String> userhelei = new HashMap<String, String>();
userhelei.put("userName", "賀雷");
userhelei.put("position", "技術(shù)網(wǎng)站負(fù)責(zé)人");
userhelei.put("webAddres", "www.ithelei.com");
Map<String, String> ithelei = new HashMap<String, String>();
ithelei.put("userName", "老大");
ithelei.put("position", "信融集團(tuán)");
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!