DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的。 (ASP.NET)
问题描述:
我正在使用ASP.NET VS2010和C#.NET作为后端语言,我没有使用MVC。 我收到一个问题,从服务器端加载数据。它显示正确的行数但没有数据。我的JSON响应使用Json字符串。DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的。 (ASP.NET)
任何人都有想法如何解决这个问题???????
这里是一个我在响应我得到
{"sEcho": 1,"iTotalRecords": 2,"iTotalDisplayRecords": 2,"aaData": [{"Name":"IT","DescEn":"Information Technology","DescAr":"testing","CreatedOn":"18-03-2013","CreatedBy":"1"},{"Name":"HR","DescEn":"Human Resource","DescAr":"testing","CreatedOn":"18-03-2013","CreatedBy":"1"}]}
绳子,下面是HTML
<table id='example' class="datatable">
<thead>
<tr>
<th>
Name
</th>
<th>
DescEn
</th>
<th>
DescAr
</th>
<th>
CreatedOn
</th>
<th>
CreatedBy
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
这里是一个JS脚本
$(document).ready(function() {
var oTable = $('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"bDestroy": true,
"sPaginationType": "full_numbers",
"aaSorting": [[1, "desc"]],
"sAjaxSource": '<%= Page.ResolveClientUrl("Request/GroupPage.aspx") %>',
"aoColumns": [
{ "aaData": "Name" },
{ "aaData": "DescEn" },
{ "aaData": "DescAr" },
{ "aaData": "CreatedOn" },
{ "aaData": "CreatedBy" }
]
});
});
任何一个有这个想法如何解决这个问题???????
答
请至少在谷歌搜索解决方案。我想我不必在这里重复相同的答案。
JSON format error even though echo matches with DataTables
+0
我已经解决了这个问题,通过创建一个类的JSON响应,然后在响应流上序列化该对象,并且此问题已解决。 – 2013-03-21 06:13:50
你如何在后端序列化对象?你正在越狱字符串至极无效json – Sergio 2013-03-19 09:01:29
我正在读取数据库中的数据,然后将该数据保存在C#字符串中用于在单词的两边加上引号我需要使用转义序列 – 2013-03-19 09:03:04
因此您将json字符串存储在数据库? – Sergio 2013-03-19 09:05:56