删除预标记 html 中第一个 json 数据中的空格

Tun*_*rry 2 html css java json

我使用框架struts,我想显示变量java中的json字符串

String test = "{\n  \"fileName\": \"\",\n  \"fileUrl\": \"\",\n  \"accountId\": ,\n  \"totalRow\": \n}";
Run Code Online (Sandbox Code Playgroud)

在浏览器上显示: 空白预标记

并查看 chrome 浏览器源代码: 源空白预标记

如何删除第一个和最后一个预标记处的空格以显示漂亮的 json 数据

Tun*_*rry 6

我发现了问题。因为struts框架的pre标签和s:property标签的距离:

错误 : 在此输入图像描述

解决:将 s:property 移至靠近预标记的位置

<pre><s:property value="test" /></pre>
Run Code Online (Sandbox Code Playgroud)

它显示漂亮的 json 数据,例如: 在此输入图像描述