java json字串格式化
//編寫方法 public static String jsonFormat(String jsonString) { JSONObject object= JSONObject.parseObject(jsonString); jsonString = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); return jsonString; }
//測試
@Test public void test() { String json = "{\"default\":{\"panelView\":{\"container\":\"tab\"},\"detailView\":{}},\"children\":{\"02\":{\"//\":[\"面板\",\"詳情\"],\"panelView\":{\"theOrder\":[\"panel\",\"searchBox\",\"customList\"],\"detailView\":{\"panel\":{\"name\":\"panel\",\"description\":\"面板載入之後初始化佈局配置\",\"layout\":\"<div id=''><\\/div>\",\"callBackAppendDom\":\"<div class='eMap-extend-panle-nav'><\\/div><div class='eMap-extend-panle-body eMap-extend-panle-body-cur'><div class='eMap-extend-panle-blank eMap-extend-city'><\\/div><\\/div><\\/div>\"},\"searchBox\":{\"name\":\"searchBox\",\"layout\":\"<div class='eMap-extend-mt15' id=''><\\/div>\",\"description\":\"搜尋框\",\"//\":\"關鍵字搜尋的欄位\",\"beanTableName\":\"*\",\"option\":{\"item\":\"請輸入搜尋關鍵字\",\"container\":\"\",\"//\":\"seachbox元件需要的樣式值\",\"inputArray\":[\"5\"]}},\"customList\":{\"name\":\"customList\",\"//\":[\"查詢url\",\"查詢條件\",\"查詢結果的欄位定義\",\"列表每條記錄顯示的詳情內容html,{欄位名}為佔位符,從beanModel中取值\"],\"url\":\"/dataOperate/query\",\"searchData\":{\"sort\":\"OBJECTID ASC\",\"select\":\"STANDARDNAME,SOURCEDATA\",\"page\":1},\"layout\":\"<div class='ipt-group eMap-extend-mt15' id='' ><\\/div>\",\"beanModel\":[{\"name\":\"OBJECTID\"},{\"name\":\"STANDARDNAME\"},{\"name\":\"SOURCEDATA\"}],\"templet\":\"<li class='eMap-list-item' id='{OBJECTID}'><div><p>名稱:<span class='eMap-txt-width'>{STANDARDNAME}<\\/span><\\/p><\\/div><div><p>地址:<span>{SOURCEDATA}<\\/span><\\/p><\\/div><\\/li>\",\"option\":{\"divId\":\"\",\"data\":{},\"pageSize\":6,\"rowClick\":\"\",\"pageShowCount\":1,\"operation\":false,\"callback\":\"\"}}}},\"detailView\":{\"//\":\"tab配置\",\"offset\":[-116,-20],\"htmlstr\":{\"tabGroup\":[{\"unique\":\"\",\"tabChange\":\"nav nav-tabs\",\"tabDiv\":\"tab-content\",\"data\":[{\"href\":\"A1-2-1_02\",\"descript\":\"基本資訊\",\"id\":\"A1-2-1_02\",\"content\":\"\"}]}]},\"Data\":[{\"name\":\"STANDARDNAME\",\"value\":\"STANDARDNAME\",\"blank\":\"\"},{\"name\":\"PROVINCE\",\"value\":\"PROVINCE\",\"blank\":\"\"},{\"name\":\"CITY\",\"value\":\"CITY\",\"blank\":\"\"},{\"name\":\"COUNTY\",\"value\":\"COUNTY\",\"blank\":\"\"},{\"name\":\"TOWN\",\"value\":\"TOWN\",\"blank\":\"\"},{\"name\":\"LATITUDE\",\"value\":\"LATITUDE\",\"blank\":\"\"},{\"name\":\"LONGITUDE\",\"value\":\"LONGITUDE\",\"blank\":\"\"},{\"name\":\"STANDARDNAMECODE\",\"value\":\"STANDARDNAMECODE\",\"blank\":\"\"},{\"name\":\"USEWAY\",\"value\":\"USEWAY\",\"blank\":\"\"},{\"name\":\"ISLANDAREA\",\"value\":\"ISLANDAREA\",\"blank\":\"\"},{\"name\":\"APPROVALYEAR\",\"value\":\"APPROVALYEAR\",\"blank\":\"\"},{\"name\":\"PROJECTNAME\",\"value\":\"PROJECTNAME\",\"blank\":\"\"},{\"name\":\"TOTALAMOUNT\",\"value\":\"TOTALAMOUNT\",\"blank\":\"\"},{\"name\":\"SEAAREA\",\"value\":\"SEAAREA\",\"blank\":\"\"},{\"name\":\"DEFINITEISLAND\",\"value\":\"DEFINITEISLAND\",\"blank\":\"\"},{\"name\":\"SOURCEDATA\",\"value\":\"資料來源\",\"blank\":\"\"},{\"name\":\"POWERUSER\",\"value\":\"使用權人\",\"blank\":\"\"},{\"name\":\"SORT\",\"value\":\"排序\",\"blank\":\"\"}]}},\"03\":{\"//\":[\"面板\",\"詳情\"],\"panelView\":{\"theOrder\":[\"panel\",\"searchBox\",\"customList\"],\"detailView\":{\"panel\":{\"name\":\"panel\",\"description\":\"面板載入之後初始化佈局配置\",\"layout\":\"<div id=''><\\/div>\",\"callBackAppendDom\":\"<div class='eMap-extend-panle-nav'><\\/div><div class='eMap-extend-panle-body eMap-extend-panle-body-cur'><div class='eMap-extend-panle-blank eMap-extend-city'><\\/div><\\/div><\\/div>\"},\"searchBox\":{\"name\":\"searchBox\",\"layout\":\"<div class='eMap-extend-mt15' id=''><\\/div>\",\"description\":\"搜尋框\",\"//\":\"關鍵字搜尋的欄位\",\"beanTableName\":\"*\",\"option\":{\"item\":\"請輸入搜尋關鍵字\",\"container\":\"\",\"//\":\"seachbox元件需要的樣式值\",\"inputArray\":[\"5\"]}},\"customList\":{\"name\":\"customList\",\"//\":[\"查詢url\",\"查詢條件\",\"查詢結果的欄位定義\",\"列表每條記錄顯示的詳情內容html,{欄位名}為佔位符,從beanModel中取值\"],\"url\":\"/dataOperate/query\",\"searchData\":{\"sort\":\"OBJECTID ASC\",\"select\":\"海島名稱,海島編號\",\"page\":1},\"layout\":\"<div class='ipt-group eMap-extend-mt15' id='' ><\\/div>\",\"beanModel\":[{\"name\":\"OBJECTID\"},{\"name\":\"海島名稱\"},{\"name\":\"海島編號\"}],\"templet\":\"<li class='eMap-list-item' id='{OBJECTID}'><div><p>名稱:<span class='eMap-txt-width'>{海島名稱}<\\/span><\\/p><\\/div><div><p>地址:<span>{海島編號}<\\/span><\\/p><\\/div><\\/li>\",\"option\":{\"divId\":\"\",\"data\":{},\"pageSize\":6,\"rowClick\":\"\",\"pageShowCount\":1,\"operation\":false,\"callback\":\"\"}}}},\"detailView\":{\"//\":\"tab配置\",\"offset\":[-116,-20],\"htmlstr\":{\"tabGroup\":[{\"unique\":\"\",\"tabChange\":\"nav nav-tabs\",\"tabDiv\":\"tab-content\",\"data\":[{\"href\":\"A1-2-1_03\",\"descript\":\"基本資訊\",\"id\":\"A1-2-1_03\",\"content\":\"\"}]}]},\"Data\":[{\"name\":\"海島名稱\",\"value\":\"海島名稱\",\"blank\":\"\"},{\"name\":\"海島編號\",\"value\":\"海島編號\",\"blank\":\"\"},{\"name\":\"岸線編號\",\"value\":\"岸線編號\",\"blank\":\"\"},{\"name\":\"影像時相\",\"value\":\"影像時相\",\"blank\":\"\"},{\"name\":\"資料來源\",\"value\":\"資料來源\",\"blank\":\"\"},{\"name\":\"繪圖人\",\"value\":\"繪圖人\",\"blank\":\"\"},{\"name\":\"稽核人\",\"value\":\"稽核人\",\"blank\":\"\"},{\"name\":\"備註\",\"value\":\"備註\",\"blank\":\"\"},{\"name\":\"岸線型別\",\"value\":\"岸線型別\",\"blank\":\"\"},{\"name\":\"岸線長度\",\"value\":\"岸線長度\",\"blank\":\"\"}]}},\"04\":{\"//\":[\"面板\",\"詳情\"],\"panelView\":{\"theOrder\":[\"panel\",\"searchBox\",\"customList\"],\"detailView\":{\"panel\":{\"name\":\"panel\",\"description\":\"面板載入之後初始化佈局配置\",\"layout\":\"<div id=''><\\/div>\",\"callBackAppendDom\":\"<div class='eMap-extend-panle-nav'><\\/div><div class='eMap-extend-panle-body eMap-extend-panle-body-cur'><div class='eMap-extend-panle-blank eMap-extend-city'><\\/div><\\/div><\\/div>\"},\"searchBox\":{\"name\":\"searchBox\",\"layout\":\"<div class='eMap-extend-mt15' id=''><\\/div>\",\"description\":\"搜尋框\",\"//\":\"關鍵字搜尋的欄位\",\"beanTableName\":\"*\",\"option\":{\"item\":\"請輸入搜尋關鍵字\",\"container\":\"\",\"//\":\"seachbox元件需要的樣式值\",\"inputArray\":[\"5\"]}},\"customList\":{\"name\":\"customList\",\"//\":[\"查詢url\",\"查詢條件\",\"查詢結果的欄位定義\",\"列表每條記錄顯示的詳情內容html,{欄位名}為佔位符,從beanModel中取值\"],\"url\":\"/dataOperate/query\",\"searchData\":{\"sort\":\"OBJECTID ASC\",\"select\":\"NAMECODE,DATASOURCE\",\"page\":1},\"layout\":\"<div class='ipt-group eMap-extend-mt15' id='' ><\\/div>\",\"beanModel\":[{\"name\":\"OBJECTID\"},{\"name\":\"NAMECODE\"},{\"name\":\"DATASOURCE\"}],\"templet\":\"<li class='eMap-list-item' id='{OBJECTID}'><div><p>名稱:<span class='eMap-txt-width'>{NAMECODE}<\\/span><\\/p><\\/div><div><p>地址:<span>{DATASOURCE}<\\/span><\\/p><\\/div><\\/li>\",\"option\":{\"divId\":\"\",\"data\":{},\"pageSize\":6,\"rowClick\":\"\",\"pageShowCount\":1,\"operation\":false,\"callback\":\"\"}}}},\"detailView\":{\"//\":\"tab配置\",\"offset\":[-116,-20],\"htmlstr\":{\"tabGroup\":[{\"unique\":\"\",\"tabChange\":\"nav nav-tabs\",\"tabDiv\":\"tab-content\",\"data\":[{\"href\":\"A1-2-1_04\",\"descript\":\"基本資訊\",\"id\":\"A1-2-1_04\",\"content\":\"\"}]}]},\"Data\":[{\"name\":\"ID\",\"value\":\"ID\",\"blank\":\"\"},{\"name\":\"REMARK\",\"value\":\"備註\",\"blank\":\"\"},{\"name\":\"AREACODE\",\"value\":\"AREACODE\",\"blank\":\"\"},{\"name\":\"NAMECODE\",\"value\":\"NAMECODE\",\"blank\":\"\"},{\"name\":\"USINGNAME\",\"value\":\"USINGNAME\",\"blank\":\"\"},{\"name\":\"STANDARDNAME\",\"value\":\"STANDARDNAME\",\"blank\":\"\"},{\"name\":\"PROVINCE\",\"value\":\"PROVINCE\",\"blank\":\"\"},{\"name\":\"CITY\",\"value\":\"CITY\",\"blank\":\"\"},{\"name\":\"COUNTY\",\"value\":\"COUNTY\",\"blank\":\"\"},{\"name\":\"TOWN\",\"value\":\"TOWN\",\"blank\":\"\"},{\"name\":\"REGISTEREDPOPULATION\",\"value\":\"REGISTEREDPOPULATION\",\"blank\":\"\"},{\"name\":\"SEAAREA\",\"value\":\"SEAAREA\",\"blank\":\"\"},{\"name\":\"FORMERNAME\",\"value\":\"FORMERNAME\",\"blank\":\"\"},{\"name\":\"PERMANENTPOPULATION\",\"value\":\"PERMANENTPOPULATION\",\"blank\":\"\"},{\"name\":\"LANDDISTANCE\",\"value\":\"LANDDISTANCE\",\"blank\":\"\"},{\"name\":\"PINYIN\",\"value\":\"PINYIN\",\"blank\":\"\"},{\"name\":\"LATITUDE\",\"value\":\"LATITUDE\",\"blank\":\"\"},{\"name\":\"LONGITUDE\",\"value\":\"LONGITUDE\",\"blank\":\"\"},{\"name\":\"MATERIALTYPE\",\"value\":\"MATERIALTYPE\",\"blank\":\"\"},{\"name\":\"VEGETATION\",\"value\":\"VEGETATION\",\"blank\":\"\"},{\"name\":\"STANDARDNAMECODE\",\"value\":\"STANDARDNAMECODE\",\"blank\":\"\"},{\"name\":\"SPECIALDEVELOPMENTTYPE\",\"value\":\"SPECIALDEVELOPMENTTYPE\",\"blank\":\"\"},{\"name\":\"GENERALDEVELOPMENTTYPE\",\"value\":\"GENERALDEVELOPMENTTYPE\",\"blank\":\"\"},{\"name\":\"ECOISLANDREEF\",\"value\":\"ECOISLANDREEF\",\"blank\":\"\"},{\"name\":\"PRELAWISLAND\",\"value\":\"PRELAWISLAND\",\"blank\":\"\"},{\"name\":\"DEFINITEISLAND\",\"value\":\"DEFINITEISLAND\",\"blank\":\"\"},{\"name\":\"STATION\",\"value\":\"STATION\",\"blank\":\"\"},{\"name\":\"ISLANDCLASS\",\"value\":\"海島分類\",\"blank\":\"\"},{\"name\":\"SHORELINELENGTH\",\"value\":\"岸線長度\",\"blank\":\"\"},{\"name\":\"DATASOURCE\",\"value\":\"資料來源\",\"blank\":\"\"},{\"name\":\"SDE.HD_DMPCD.AREA\",\"value\":\"面積\",\"blank\":\"\"},{\"name\":\"SORT\",\"value\":\"排序\",\"blank\":\"\"}]}}}}"; String jsonString = jsonFormat(json); System.out.println(jsonString); }
//結果
{
"default":{
"detailView":{},
"panelView":{
"container":"tab"
}
},
"children":{
"02":{
"//":[
"面板",
"詳情"
],
"detailView":{
"//":"tab配置",
"offset":[
-116,
-20
],
"Data":[
{
"blank":"",
"name":"STANDARDNAME",
"value":"STANDARDNAME"
},
{
"blank":"",
"name":"PROVINCE",
"value":"PROVINCE"
},
{
"blank":"",
"name":"CITY",
"value":"CITY"
},
{
"blank":"",
"name":"COUNTY",
"value":"COUNTY"
},
{
"blank":"",
"name":"TOWN",
"value":"TOWN"
},
{
"blank":"",
"name":"LATITUDE",
"value":"LATITUDE"
},
{
"blank":"",
"name":"LONGITUDE",
"value":"LONGITUDE"
},
{
"blank":"",
"name":"STANDARDNAMECODE",
"value":"STANDARDNAMECODE"
},
{
"blank":"",
"name":"USEWAY",
"value":"USEWAY"
},
{
"blank":"",
"name":"ISLANDAREA",
"value":"ISLANDAREA"
},
{
"blank":"",
"name":"APPROVALYEAR",
"value":"APPROVALYEAR"
},
{
"blank":"",
"name":"PROJECTNAME",
"value":"PROJECTNAME"
},
{
"blank":"",
"name":"TOTALAMOUNT",
"value":"TOTALAMOUNT"
},
{
"blank":"",
"name":"SEAAREA",
"value":"SEAAREA"
},
{
"blank":"",
"name":"DEFINITEISLAND",
"value":"DEFINITEISLAND"
},
{
"blank":"",
"name":"SOURCEDATA",
"value":"資料來源"
},
{
"blank":"",
"name":"POWERUSER",
"value":"使用權人"
},
{
"blank":"",
"name":"SORT",
"value":"排序"
}
],
"htmlstr":{
"tabGroup":[
{
"data":[
{
"href":"A1-2-1_02",
"id":"A1-2-1_02",
"descript":"基本資訊",
"content":""
}
],
"unique":"",
"tabChange":"nav nav-tabs",
"tabDiv":"tab-content"
}
]
}
},
"panelView":{
"theOrder":[
"panel",
"searchBox",
"customList"
],
"detailView":{
"customList":{
"//":[
"查詢url",
"查詢條件",
"查詢結果的欄位定義",
"列表每條記錄顯示的詳情內容html,{欄位名}為佔位符,從beanModel中取值"
],
"layout":"<div class='ipt-group eMap-extend-mt15' id='' ></div>",
"beanModel":[
{
"name":"OBJECTID"
},
{
"name":"STANDARDNAME"
},
{
"name":"SOURCEDATA"
}
],
"templet":"<li class='eMap-list-item' id='{OBJECTID}'><div><p>名稱:<span class='eMap-txt-width'>{STANDARDNAME}</span></p></div><div><p>地址:<span>{SOURCEDATA}</span></p></div></li>",
"name":"customList",
"searchData":{
"select":"STANDARDNAME,SOURCEDATA",
"sort":"OBJECTID ASC",
"page":1
},
"url":"/dataOperate/query",
"option":{
"pageShowCount":1,
"rowClick":"",
"data":{},
"pageSize":6,
"callback":"",
"operation":false,
"divId":""
}
},
"panel":{
"layout":"<div id=''></div>",
"callBackAppendDom":"<div class='eMap-extend-panle-nav'></div><div class='eMap-extend-panle-body eMap-extend-panle-body-cur'><div class='eMap-extend-panle-blank eMap-extend-city'></div></div></div>",
"name":"panel",
"description":"面板載入之後初始化佈局配置"
},
"searchBox":{
"layout":"<div class='eMap-extend-mt15' id=''></div>",
"//":"關鍵字搜尋的欄位",
"beanTableName":"*",
"name":"searchBox",
"description":"搜尋框",
"option":{
"container":"",
"//":"seachbox元件需要的樣式值",
"inputArray":[
"5"
],
"item":"請輸入搜尋關鍵字"
}
}
}
}
},
"03":{
"//":[
"面板",
"詳情"
],
"detailView":{
"//":"tab配置",
"offset":[
-116,
-20
],
"Data":[
{
"blank":"",
"name":"海島名稱",
"value":"海島名稱"
},
{
"blank":"",
"name":"海島編號",
"value":"海島編號"
},
{
"blank":"",
"name":"岸線編號",
"value":"岸線編號"
},
{
"blank":"",
"name":"影像時相",
"value":"影像時相"
},
{
"blank":"",
"name":"資料來源",
"value":"資料來源"
},
{
"blank":"",
"name":"繪圖人",
"value":"繪圖人"
},
{
"blank":"",
"name":"稽核人",
"value":"稽核人"
},
{
"blank":"",
"name":"備註",
"value":"備註"
},
{
"blank":"",
"name":"岸線型別",
"value":"岸線型別"
},
{
"blank":"",
"name":"岸線長度",
"value":"岸線長度"
}
],
"htmlstr":{
"tabGroup":[
{
"data":[
{
"href":"A1-2-1_03",
"id":"A1-2-1_03",
"descript":"基本資訊",
"content":""
}
],
"unique":"",
"tabChange":"nav nav-tabs",
"tabDiv":"tab-content"
}
]
}
},
"panelView":{
"theOrder":[
"panel",
"searchBox",
"customList"
],
"detailView":{
"customList":{
"//":[
"查詢url",
"查詢條件",
"查詢結果的欄位定義",
"列表每條記錄顯示的詳情內容html,{欄位名}為佔位符,從beanModel中取值"
],
"layout":"<div class='ipt-group eMap-extend-mt15' id='' ></div>",
"beanModel":[
{
"name":"OBJECTID"
},
{
"name":"海島名稱"
},
{
"name":"海島編號"
}
],
"templet":"<li class='eMap-list-item' id='{OBJECTID}'><div><p>名稱:<span class='eMap-txt-width'>{海島名稱}</span></p></div><div><p>地址:<span>{海島編號}</span></p></div></li>",
"name":"customList",
"searchData":{
"select":"海島名稱,海島編號",
"sort":"OBJECTID ASC",
"page":1
},
"url":"/dataOperate/query",
"option":{
"pageShowCount":1,
"rowClick":"",
"data":{},
"pageSize":6,
"callback":"",
"operation":false,
"divId":""
}
},
"panel":{
"layout":"<div id=''></div>",
"callBackAppendDom":"<div class='eMap-extend-panle-nav'></div><div class='eMap-extend-panle-body eMap-extend-panle-body-cur'><div class='eMap-extend-panle-blank eMap-extend-city'></div></div></div>",
"name":"panel",
"description":"面板載入之後初始化佈局配置"
},
"searchBox":{
"layout":"<div class='eMap-extend-mt15' id=''></div>",
"//":"關鍵字搜尋的欄位",
"beanTableName":"*",
"name":"searchBox",
"description":"搜尋框",
"option":{
"container":"",
"//":"seachbox元件需要的樣式值",
"inputArray":[
"5"
],
"item":"請輸入搜尋關鍵字"
}
}
}
}
},
"04":{
"//":[
"面板",
"詳情"
],
"detailView":{
"//":"tab配置",
"offset":[
-116,
-20
],
"Data":[
{
"blank":"",
"name":"ID",
"value":"ID"
},
{
"blank":"",
"name":"REMARK",
"value":"備註"
},
{
"blank":"",
"name":"AREACODE",
"value":"AREACODE"
},
{
"blank":"",
"name":"NAMECODE",
"value":"NAMECODE"
},
{
"blank":"",
"name":"USINGNAME",
"value":"USINGNAME"
},
{
"blank":"",
"name":"STANDARDNAME",
"value":"STANDARDNAME"
},
{
"blank":"",
"name":"PROVINCE",
"value":"PROVINCE"
},
{
"blank":"",
"name":"CITY",
"value":"CITY"
},
{
"blank":"",
"name":"COUNTY",
"value":"COUNTY"
},
{
"blank":"",
"name":"TOWN",
"value":"TOWN"
},
{
"blank":"",
"name":"REGISTEREDPOPULATION",
"value":"REGISTEREDPOPULATION"
},
{
"blank":"",
"name":"SEAAREA",
"value":"SEAAREA"
},
{
"blank":"",
"name":"FORMERNAME",
"value":"FORMERNAME"
},
{
"blank":"",
"name":"PERMANENTPOPULATION",
"value":"PERMANENTPOPULATION"
},
{
"blank":"",
"name":"LANDDISTANCE",
"value":"LANDDISTANCE"
},
{
"blank":"",
&n