简体   繁体   中英

Server unable to parse a valid json

I am making this ajax request to a url, but server is sending a response Unrecognized token 'naejzraieale': was expecting 'null', 'true', 'false' or NaN at [Source: org.eclipse.jetty.server.HttpInput@13367e3; line: 1, column: 25] Unrecognized token 'naejzraieale': was expecting 'null', 'true', 'false' or NaN at [Source: org.eclipse.jetty.server.HttpInput@13367e3; line: 1, column: 25] .

My Ajax request looks like this

$.ajax({url: "https://jsonparser.mydomain.com",
        contentType: 'application/json',
        type: "POST",
        data :{name : "juzer ali",
               email : "email@gmail.com",
               how : "Used jQuery.ajax from google chromes developer console",
               urls : ["https://chrome.google.com/webstore/search/",                                  "https://chrome.google.com/webstore/detail/", 
"https://github.com", "https://docs.google.com/document/d/edit?pli=1", "pro.appspot.com"]}
});

EDIT: Please notice Unrecognized token 'naejzraieale': . the j and r in this error string is from the name property of the object I am passing in data. When I capitalize the letters, I get (Unrecognized token 'naeJZRAIeale': was expecting 'null', 'true',)

before sending data to server you need to encode it in JSON format JSON.stringify and JSON.parse are provided by latest browsers but if any browser doesn't support that then you can use a jquery plugin to do the same http://code.google.com/p/jquery-json/ , if you use this plugin then the syntax would be different a little bit

$.ajax({
       url: "https://jsonparser.mydomain.com",
       type: 'POST',
       contentType:'application/json',
       data: JSON.stringify({name : "juzer ali",
               email : "email@gmail.com",
               how : "Used jQuery.ajax from google chromes developer console",
               urls : ["https://chrome.google.com/webstore/search/",                                  "https://chrome.google.com/webstore/detail/", 
"https://github.com/", "https://docs.google.com/document/d/edit?pli=1", "pro.appspot.com"]}),
       dataType:'json'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM