Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server unable to parse a valid json

Tags:

json

jquery

ajax

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].

My Ajax request looks like this

$.ajax({url: "https://jsonparser.mydomain.com",
        contentType: 'application/json',
        type: "POST",
        data :{name : "juzer ali",
               email : "[email protected]",
               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',)

like image 322
Juzer Ali Avatar asked Mar 15 '12 19:03

Juzer Ali


People also ask

Why is JSON parse failing?

The parsing functions, parseArray() and parseObject() , may fail for 6 reasons: The input is not a valid JSON. The StaticJsonBuffer is too small. The StaticJsonBuffer is too big (stack overflow)

What is JSON data parsing?

JSON parsing is the process of converting a JSON object in text format to a Javascript object that can be used inside a program. In Javascript, the standard way to do this is by using the method JSON. parse() , as the Javascript standard specifies.


1 Answers

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 protected]",
               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'
});
like image 107
Saket Patel Avatar answered Oct 13 '22 16:10

Saket Patel