json字符串拼接

xiaoxiao2021-02-28  56

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

转载请注明原文地址: https://www.6miu.com/read-84173.html

最新回复(0)