-1
公共類的一部分我爲dataTables插件構建了一個數據結構。C#將字符串轉換爲JSON錯誤
構建數據結構中的代碼是:
var response = "{ \"data\": [";
response = response + "[";
response = response + "\"Clark, Keith\",";
response = response + "\"Corporate\",";
response = response + "\"XXX-XXX-XXXX\",";
response = response + "\"XXX-XXX-XXXX\",";
response = response + "\"[email protected]\"";
response = response + "],";
response = response + "[";
response = response + "\"Clark, Keith\",";
response = response + "\"Corporate\",";
response = response + "\"YYY-YYY-YYYY\",";
response = response + "\"YYY-YYY-YYYY\",";
response = response + "\"[email protected]\"";
response = response + "]";
response = response + "] }";
return response;
此運行良好並創建表按預期方式。我遇到的問題是當我嘗試將HTML標記添加到字段時。我想使用的字體真棒圖標旁邊的名稱來表示這樣的狀態:
<i class="fa fa-arrow-up" style="color: #00ff00;" aria-hidden="true">
我試圖修改我的代碼如下:
response = response + "\"<i class=\"\"fa fa-arrow-up\"\" style=\"\"color: #00ff00;\"\" aria-hidden=\"\"true\"\">Clark, Keith\",";
但現在我收到了一條錯誤的JSON格式不正確。我是否錯過了某些東西,或者HTML標記不能在JSON結構中使用?
你不會錯過任何東西,html標記是無效的JSON。 JSON字符串必須完全獨立。 –
發佈帶有新東西的json。在最後關閉之後,你是不是想添加它? – Dispersia
@JonathonChase html中沒有任何問題,html只是靜態文本,這正是JSON擅長的。 – Dispersia