I’m using jquery.parseJSON() but it is not happening. What I’m doing is making an ajax call to server and then on success I try to parse data got from the server using jquery.parseJSON() but it is not working.
function getIdVals(id){
$.ajax(
{
url: "MyServlet",
data: "Id="+id,
cache: false,
success: function(html){
alert(html);
var obj = jquery.parseJSON(html);
alert(obj.data);
}
}
);
}
The response I got from server is something like below:
'{ "data" : "{ aas:five,asda:five,alskjaskdakbd:two,test:two,asddas:five,
lasnd:five,ad:five,this:two,smd:five,alskjaskdakbdals:four,}"}'
When I try to put the above string in jquery.parseJSON function it works fine but don’t know why writing it as jquery.parseJSON(html) doesn’t work.
How can I solve this?
the json you are getting is in valid it should be something like
and then as @zerkms answered