Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Help me Please. JSON object SyntaxError: JSON Parse error: Unterminated string

JAVA code

    @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 code

    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);
        }

    });
}

Error code

    SyntaxError: JSON Parse error: Unterminated string

Help me Please. and json output

{"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 "}
share|improve this question
 
It would be easier if you use some library (such as Jackson) to build your JSON responses. wiki.fasterxml.com/JacksonHome –  Pavel Horal Jun 21 '13 at 8:41
add comment

2 Answers

This does not look like valid json, try the below to see if it then will send.

data = {
            "key": "job1"
        }
share|improve this answer
add comment

I am not sure, what do you want to do with line. url : "<c:url value="/"/>" + "getMessage.htm",

If this is nexted string value, try this single codes instead of double.

url : "<c:url value='/'/>" + "getMessage.htm"
share|improve this answer
 
c:url will get to the base location of the webapp so you don't have to do ../ each time you get further down the url path. It gets rendered by the JSP. –  david99world Jun 21 '13 at 8:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.