解析/字符串化'<>'来自json的价值

时间:2016-04-22 10:57:45

标签: json parsing stringify

"newdynaid": 22,
"isPrimary": "Y",
"isNotNull": "Y",
"scalePrecision": "",
"checkConstraint": "(ABC<>(0))",
"isUnique": "N",
"name": "INDV_ID",
"sizeUnits": "",
"foreignConstraint": "",

我有上面需要在JSP上显示的json片段。我尝试过stringify和parse选项来考虑'&lt;&gt;'作为字符串值,并且在此之后不终止JSON字符串但无法执行此操作。 @BalusC,我希望你能在那里帮助我。

1 个答案:

答案 0 :(得分:0)

最后一个逗号将成为一个问题。此外,我不确定你要做什么。这是我最好的猜测:

&#13;
&#13;
var data={"newdynaid": 22,
"isPrimary": "Y",
"isNotNull": "Y",
"scalePrecision": "",
"checkConstraint": "(ABC<>(0))",
"isUnique": "N",
"name": "INDV_ID",
"sizeUnits": "",
"foreignConstraint": ""};

function show() {
  document.getElementById("out").textContent=JSON.stringify(data).replace(/,/g,",\n");
}
&#13;
<input type="button" value="Show" onclick="show();"><pre id="out"></pre>
&#13;
&#13;
&#13;