fastjson json和java对象互相转换

    Log log = new Log();
    String s = JSON.toJSONString(log);
    
    String jsonLog =  "{\"date\":1,\"name\":\"zhangsan\"}";
    Log log = JSON.parseObject(jsonLog, Log.class);

    List list = new ArrayList<>();
    list.add(log1);
    list.add(log2);
    
    String listLog =  JSON.toJSONString(list);
    String listJson1 = "[{\"clientId\":1,\"name\":\"zhangsan\"},{\"clientId\":2,\"name\":\"lisi\"}]";
    List list1 = JSON.parseArray(listJson1, Log.class);


    String string= "{\"clientId\":\"xxx\",\"level\":x,\"ip\":\"xxxxx\",\"cmpId\":\"1\",\"logs\":[{\"date\":\"2019-xxxx 18:19:51\",\"verify_type\":\"xxx\",\"pin\":\"xxx\",\"status\":\"x\"}],\"channelId\":\"xxxx\"}";
    CheckLog里面logs字段 ArrayList logs;
    CheckLog checkLog = JSONObject.parseObject(string, CheckLog.class);

你可能感兴趣的:(java)