当前位置 博文首页 > u010786200的博客:json字符串拼接

    u010786200的博客:json字符串拼接

    作者:[db:作者] 时间:2021-07-06 12:25

    package com.demo;




    public class test {


    public static void main(String[] args) {
    //普通拼接
    String str = "{\"errcode\":0,\"errmsg\":\"ok\",\"msgid\":\"200228332\"}";
    System.out.println("第一种");
    System.out.println(str);
    //普通换行拼接
    String str1 = "{\n\"errcode\":0,\n\"errmsg\":\"ok\",\n\"msgid\":\"200228332\"\n}";
    System.out.println("第二种");
    System.out.println(str1);
    //进阶换行拼接
    String str2 = "{\n"+
    ? "\"g\":1,\n"+
    ? ? ? "\"h\":2,\n"+
    ? "\"data\":{\n" +
    ? " ? ? ? ? \"first\": {\n" +
    ? " ? ? ? ? ? ?\"value\":\"" + 1 +"\",\n" +
    ? " ? ?\"color\":\"#173177\"\n" +
    ? " },\n" +
    ? " ? ? ? ?\"keyword1\":{\n" +
    ? " ? ? ? ? \"value\":\"" + 2 +"\",\n" +
    ? " \"color\":\"#173177\"\n" +
    ? " },\n" +
    ? " \"keyword2\":{\n" +
    ? " \"value\":\"" + 3 +"\",\n" +
    ? " \"color\":\"#173177\"\n" +
    ? " },\n"+
    ? " \"remarks\":{\n"+
    ? " \"value\":\""+123+"\",\n"+
    ? " \"color\":\"#173177\"\n"+
    ? " }\n"+
    ? " }";
    System.out.println("第三种");
    System.out.println(str2);
    }
    }

    cs