Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从服务器解析JSON数据_Java_Jquery_Json_Spring_Spring Mvc - Fatal编程技术网

Java 无法从服务器解析JSON数据

Java 无法从服务器解析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>

我在firefox中遇到错误:

DataTables警告(表id='alertfilters'):DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的

我正在使用ajax在jsp中显示表

HTML

<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"
    }]
}
调试my
getFilters
方法返回语句的屏幕截图。


我想这可能是因为我在回复中得到了这些{}&,但我不知道为什么我会得到这些。知道我遗漏了什么吗?

{}&
会使您的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"
    }]
}