Here’s an answer in return for your answer on REST API example
This just shows you the actual message, properly decoded.
var strServerResponse = "{"errors":[{"errorMessage":"Device ID inv\\u00e1lido"}]}";
function rhtmlspecialchars(str) {
// Remove HTML Special characters first
if (typeof(str) == "string") {
str = str.replace(/>/ig, ">");
str = str.replace(/</ig, "<");
str = str.replace(/'/g, "'");
str = str.replace(/"/ig, '"');
str = str.replace(/&/ig, '&'); /* must do & last */
}
return str;
}
// First remove the html special characters
var strServerResponseWOspecialChars = rhtmlspecialchars(strServerResponse);
// Use JSON parse to turn it into a JSON Object
var jsonObj = JSON.parse(strServerResponseWOspecialChars);
// Now easily pull out the stuff we need from this object
alert(jsonObj.errors[0].errorMessage); // assuming that the message is in this format "{'errors':[{'errorMessage':'Device ID inválido'}]}"
Cheers,
M.M