IntelliJ idea how to generate dynamic JSON string

The first step: first write the following basic procedures

package cn.lianxi.cn.lianxi.json;

/**
 * @Author: Wxz
 * @Date: 2020/8/19 16:45
 */
public class test1 {
    public static void main(String[] args) {
        //需要动态修改的字符串
        String name ="大王";
        //需要动态修改的int值
        int age = 18;
        //需要生成的json字符串
        String jsonstr="";
    }
}

Step 2: Follow the steps below

 

Step 3: Choose Json

Step 4: Operate as shown

Step 5: Choose as follows

Step 6: Write a string in the pop-up box according to the following format, save and press Ctrl + F4 to exit

Step 7: Splicing by yourself, the corresponding code is as follows:

package cn.lianxi.cn.lianxi.json;

/**
 * @Author: Wxz
 * @Date: 2020/8/19 16:45
 */
public class test1 {
    public static void main(String[] args) {
        //需要动态修改的字符串
        String name ="大王";
        //需要动态修改的int值
        int age = 18;
        //需要生成的json字符串
        String jsonstr= "{\n" +
                "  \"name\":"+name+",\n" +
                "  \"age\": "+age+",\n" +
                "  \"sex\": \"男\"\n" +
                "}";
        System.out.println(jsonstr);
    }
}

Step 8: Print out

Hope it is useful to everyone!

 

 

 

 

Guess you like

Origin blog.csdn.net/xgysimida/article/details/108104645