【问题标题】:Error JSON object SyntaxError: JSON Parse error: Unterminated string withSpring MVC错误 JSON object SyntaxError: JSON Parse error: Unterminated string withSpring MVC
【发布时间】:2013-06-21 08:27:54
【问题描述】:

请帮帮我。 JSON 对象 SyntaxError:JSON 解析错误:未终止的字符串

JAVA代码

    @RequestMapping(value = "getMessage.htm")
public @ResponseBody String getStatusServer(ModelMap model, HttpSession session,@RequestParam("key") String key)
        throws InterruptedException, ExecutionException {
    BufferData bufferData = DataMap.dataMap.get(key);
    StringBuilder content = new StringBuilder();
    content.append("{\"status\":").append(bufferData.getStatus()).append(",").append("  \"messages\": \"").append(bufferData.getMess()).append("\"}");
    System.out.println(content.toString());

    return content.toString();
}

JQuery 代码

    function getMessage() {

    $.ajax({
        type : 'GET',
        url : "<c:url value="/"/>" + "getMessage.htm",
        data : 'key=' + 'job1',
        dataType : "json",
        success : function(data) {
            alert("test");
            alert(JSON.stringify(data));
        },
        error : function(data, status, er) {
            alert("error: " + data + " status: " + status + " er:" + er);
        }

    });
}

错误代码

    SyntaxError: JSON Parse error: Unterminated string

请帮帮我。 和json输出

{"status":1, "messages":"Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic x86_64) * Documentation: https://help.ubuntu.com/ System information as of Fri Jun 21 17:13:41 ICT 2013 System load: 0.08 Processes: 265 Usage of /: 13.9% of 38.02GB Users logged in: 2 Memory usage: 51% IP address for eth0: 10.216.92.20 Swap usage: 31% => There are 2 zombie processes. Graph this data and manage this system at https://landscape.canonical.com/ Last login: Fri Jun 21 16:30:33 2013 from wachirawat.local vos1@icenaja:~$ hostname icenaja vos1@icenaja:~$ pwd /home/vos1 vos1@icenaja:~$ exit logout "}

【问题讨论】:

标签: java jquery json spring


【解决方案1】:

这看起来不像是有效的 json,试试下面看看它是否会发送。

data = {
            "key": "job1"
        }

【讨论】:

    【解决方案2】:

    我不确定,你想用 line 做什么。 url : "&lt;c:url value="/"/&gt;" + "getMessage.htm",

    如果这是下一个字符串值,试试这个单代码而不是双代码。

    url : "<c:url value='/'/>" + "getMessage.htm"
    

    【讨论】:

    • c:url 将到达 web 应用程序的基本位置,因此您不必每次在 url 路径的下方执行../。它由 JSP 呈现。
    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 2021-11-09
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    相关资源
    最近更新 更多