json字符串拼接

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);
}
}

猜你喜欢

转载自blog.csdn.net/u010786200/article/details/72921731
今日推荐