BusinessInfo.java 3.6 KB
Newer Older
1 2
package com.kwan.springbootkwan.entity.resp;

3 4
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
5 6 7 8 9 10
import lombok.Data;

import java.util.List;

@Data
public class BusinessInfo {
11

12 13 14 15 16 17 18 19 20 21 22 23 24 25
    private String traceId;
    private Integer code;
    private ArticleData data;
    private String message;

    @Data
    public static class ArticleData {
        public Object total;
        public List<Article> list;

        @Data
        public static class Article {
            public String formatTime;
            public Integer collectCount;
26
            public Integer source;
27 28 29 30 31 32 33 34 35 36 37 38
            public String description;
            public Integer diggCount;
            public String type;
            public String title;
            public Boolean hasOriginal;
            public String url;
            public Integer commentCount;
            public String rtype;
            public Long postTime;
            public String editUrl;
            public Long createTime;
            public Integer articleType;
39
            public List<Object> picList;
40
            public Integer viewCount;
41 42 43 44 45 46 47 48 49 50 51 52 53 54
            public Object expandTitle;
            public Object cover;
        }
    }

    public static void main(String[] args) {
        String body = " {\"code\":200,\"message\":\"success\",\"traceId\":\"56e59727-b0e5-4017-b613-3bfb9dbee864\",\"data\":{\"list\":[{\"type\":\"blog\",\"formatTime\":\"12 分钟前\",\"title\":\"【实战项目】从0到1实现高并发内存池(上)\",\"description\":\"\u200B本篇文章是实现一个高并发的内存池,他的原型是google的一个开源项目tcmalloc(tcmalloc源码),tcmalloc全称Thread-Caching Malloc,即线程缓存的malloc,是一种用于内存分配和管理的内存分配器(内存池)。这个项目旨在提高多线程应用程序的性能,实现了高效的多线程内存管理。\",\"hasOriginal\":true,\"diggCount\":4,\"commentCount\":3,\"postTime\":1698045098000,\"createTime\":1697553615000,\"url\":\"https://blog.csdn.net/weixin_67596609/article/details/133895730\",\"articleType\":1,\"viewCount\":36,\"picList\":[\"https://img-blog.csdnimg.cn/b7634b29af834f9d88cad6ba1de0258a.png\"],\"editUrl\":\"https://mp.csdn.net/console/editor/html/133895730\",\"collectCount\":3,\"rtype\":\"article\"},{\"type\":\"blink\",\"formatTime\":\"昨天 10:40\",\"title\":\"前几天由于一些原因,没有更新文章。最近要开始持续更新啦!\\nps:想多了全是问题,做多了全是答案!加油!\\n\",\"picList\":[{\"thumbnail\":\"https://userblink.csdnimg.cn/6748783d6e974f5da67346c6b0e9b2f0.png?x-oss-process=image/interlace,1/format,jpg/resize,w_375\",\"url\":\"https://userblink.csdnimg.cn/6748783d6e974f5da67346c6b0e9b2f0.png\"}],\"createTime\":1697942415000,\"url\":\"https://blink.csdn.net/details/1591445\",\"source\":1,\"expandTitle\":null,\"cover\":null,\"rtype\":\"picture\"}],\"total\":null}}";
        ObjectMapper objectMapper = new ObjectMapper();
        BusinessInfo businessInfo = null;
        try {
            businessInfo = objectMapper.readValue(body, BusinessInfo.class);
            System.out.println(businessInfo);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
55
        }
56 57 58 59 60 61 62
        final BusinessInfo.ArticleData data = businessInfo.getData();
        final List<BusinessInfo.ArticleData.Article> list = data.getList();
        final BusinessInfo.ArticleData.Article article = list.get(0);
        final String type = article.getType();
        final String urlInfo = article.getUrl();
        System.out.println(type);
        System.out.println(urlInfo);
63 64
    }
}