使用ssh+ligerUI發現struts2返回json值格式有個奇怪的現象
json類型
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult" />
</result-types>
<action name="intoListView" class="" method="intoListView">
<span style="white-space:pre"> </span><result name="success" type="json">
</result>
</action>
前端頁面
var schdJsonArray = '<s:property value="schdJson" escapeHtml="false" />';
console.log(schdJsonArray);
瀏覽器控制檯輸出格式正確
[{"staffname":"李四"},{"staffname":"張三"}]
</pre><pre code_snippet_id="497916" snippet_file_name="blog_20141027_6_4194355" name="code" class="html">且可以直接轉換成json對象
</pre><pre code_snippet_id="497916" snippet_file_name="blog_20141027_8_9470094" name="code" class="html">var schdJsonArray = '<s:property value="schdJson" />';
console.log(schdJsonArray);
這樣的話,輸出爲:
[{"staffname":"李四"},{"staffname":"張三"}]
不能直接轉換成json對象
但是使用
s:property
取值,頁面上都顯示爲
[{"staffname":"李四"},{"staffname":"張三"}]