I make a xhrget request to my servlet in dojo. Response is a json object or json array.
But when print the response it gives as Object[] object. How to get the json objects as it was send?
What do you mean by "print" the response? If you convert an object to a string (via document.write, for instance) then it renders as the strange [object Object]
.
You can use console.log instead of printing it to the debugging console, do this
press F12 on Chrome / IE to make that appear
you may need specify "handleAs" attribute with "json" in ioArgs to parse the response text as Json object:
var xhrArgs = {
url: "/foo/bar.json", // uri to your remote json resource
handleAs: "json",
load: function(data, ioargs) {
// data is the parsed JavaScript object you want
},
error: function(error, ioargs) {
}
}
//Call the asynchronous xhrGet
var deferred = dojo.xhrGet(xhrArgs);
Or you get respond string only that contains json representation. then parse it with dojo.toJson in your load callback function:
var obj = dojo.toJson(data);