I am trying to access a value from an JsonObject, retrieved via jqXHR.responseText from the backend which is written in Java.
Data returned as Streaming Output by backend:
...
String msg = "{'msgkey':'my message to the world'}";
return JSON.defaultJSON().forValue(msg);
...
Access via ajax-call, here the done-callback-function:
....
$.ajax({
type: "GET",
contentType: "application/json",
url: url,
dataType: "json"
}).done(function (data, status, jqXHR) {
var resJson = jqXHR.responseText;
console.log("done jqXHR.responseText " + resJson);
var help = jQuery.parseJSON(resJson);
console.log("done help.status: " + help.status);
....
Result is: help.status undefined.
Why? Is parsing or the '' wrong? I guess I missed to create an object, but I have no clue why it does not work.
I tried the small example, which is on th jQuery-site, which works perfectly fine:
var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );
Any ideas?
Thanks
dataType: 'json'to the ajax request... then no need to parse the value your self... also write an error handler to see whether there are any parse errors"not'...msgvariable is already a string in almost JSON format (it would be JSON if you used the correct quote character as already mentioned), so what is theJSON.defaultJSON().forValue(msg)part supposed to do?