示例#1
0
 /** 测试 */
 public static void main(String[] args) {
   List<Map<String, Object>> list = Lists.newArrayList();
   Map<String, Object> map = Maps.newHashMap();
   map.put("id", 1);
   map.put("pId", -1);
   map.put("name", "根节点");
   list.add(map);
   map = Maps.newHashMap();
   map.put("id", 2);
   map.put("pId", 1);
   map.put("name", "你好");
   map.put("open", true);
   list.add(map);
   String json = JsonMapper.getInstance().toJson(list);
   System.out.println(json);
   System.out.println(JsonMapper.getInstance().toJson(map));
 }
示例#2
0
 /**
  * 转换为JSON字符串
  *
  * @param object
  * @return
  */
 public static String toJsonString(Object object) {
   return JsonMapper.getInstance().toJson(object);
 }