Java 无法从服务器解析JSON数据
我在firefox中遇到错误: DataTables警告(表id='alertfilters'):DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的 我正在使用ajax在jsp中显示表 HTMLJava 无法从服务器解析JSON数据,java,jquery,json,spring,spring-mvc,Java,Jquery,Json,Spring,Spring Mvc,我在firefox中遇到错误: DataTables警告(表id='alertfilters'):DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的 我正在使用ajax在jsp中显示表 HTML <table id="alertfilters" class="display" style="width: 100%; border-spacing: 0px;" > <thead> <tr>
<table id="alertfilters" class="display" style="width: 100%; border-spacing: 0px;" >
<thead>
<tr>
<th>User Name</th>
<th>Expiration Time</th>
<th>Last Matched Time</th>
<th>State</th>
<th>Matched Today Count</th>
<th>Use RegEx</th>
</tr>
</thead>
</table>
在firebug响应中,我可以看到:
{}
&&
{
"data": [{
"activationTime": "1969-12-31T19:00:00.000-0500",
"description": "Set permanent alert filter ",
"expirationTime": "1969-12-31T19:00:00.000-0500",
"hosts": "asdfrd",
"lastMatchedTime": "2012-09-08T10:34:27.501-0400",
"matchStrings": "psl[0-9]",
"matchedTodayCount": "0",
"nameValuePairs": "",
"objectId": "212121",
"state": "PERMANENT",
"useRegEx": "true",
"userName": "z111111z"
}]
}
调试mygetFilters
方法返回语句的屏幕截图。:
我想这可能是因为我在回复中得到了这些{}&,但我不知道为什么我会得到这些。知道我遗漏了什么吗?
{}&
会使您的json无效。这是事实。
能否尝试调试getFilters
方法,并确保json
变量返回正确的json?方法getFilters()没有返回JSONObject
因为您没有使用添加JSONObject
您需要在方法上方添加注释,并在中选择响应类型而不是application/json
有关更多详细信息,请参阅
或
您只需在方法上放置注释即可请从服务器端向我显示更多详细信息,似乎您在这段代码
返回json之后完成了后期处理代码>还是什么before@mshaaban我怀疑,无论如何,我现在已经添加了整个控制器方法。
$(document).ready(function() {
$('#alertfilters').dataTable( {
"sAjaxSource" : 'getFilters/${sessionScope.monitorServerName}/',
"columns": [
{ "data": "userName" },
{ "data": "expirationTime" },
{ "data": "lastMatchedTime" },
{ "data": "state" },
{ "data": "matchedTodayCount" },
{ "data": "useRegEx" }
]
} );
} );
{}
&&
{
"data": [{
"activationTime": "1969-12-31T19:00:00.000-0500",
"description": "Set permanent alert filter ",
"expirationTime": "1969-12-31T19:00:00.000-0500",
"hosts": "asdfrd",
"lastMatchedTime": "2012-09-08T10:34:27.501-0400",
"matchStrings": "psl[0-9]",
"matchedTodayCount": "0",
"nameValuePairs": "",
"objectId": "212121",
"state": "PERMANENT",
"useRegEx": "true",
"userName": "z111111z"
}]
}