利用工具包进行json转换

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: jdk17Test
 * @author: quxiao
 * @create: 2023-12-21 15:56
 **/
public class T3 {
    static class quiao {
        @Override
        public String toString() {
            return "quiao{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }

        String name;
        int age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public quiao(String name, int age) {
            this.name = name;
            this.age = age;
        }
    }

    public static void main(String[] args) {
        List list = new ArrayList<>();
        list.add(new quiao("gagas", 18));
        list.add(new quiao("gagas", 18));
        list.add(new quiao("gagas", 18));
        list.add(new quiao("gagas", 18));
        String s = JSONObject.toJSONString(list);
        List quiaos = JSONObject.parseArray(s, quiao.class);
        System.out.println(quiaos);
    }

    static void t1() {
        List list = new ArrayList<>();
        list.add("123");
        list.add("456");
        String toJSONString = JSONObject.toJSONString(list);
        System.out.println(toJSONString);
        List list1 = JSONObject.parseArray(toJSONString, String.class);
        System.out.println(list1);
    }
}

    com.alibaba
    fastjson
    2.0.25

还是学springmvc的时候,用了一次这个 ,转眼一年多就过去了,工作突然用到了,记个笔记吧

你可能感兴趣的:(工具类,json,windows)