I need to find my string is XML or JSON object or string, based on this response I will make the string looks pretty.
So for that, I need to identify what kind of object. Can anyone please help me to find a way to achieve this?
Thanks in advance.
I need to find my string is XML or JSON object or string, based on this response I will make the string looks pretty.
So for that, I need to identify what kind of object. Can anyone please help me to find a way to achieve this?
Thanks in advance.
try like this
function GetInputType(response) {
try {
//try to parse via json
a = JSON.parse(response);
return 'json type';
} catch(e) {
//try xml parsing
let parser = new DOMParser;
var xmlDoc = parser.parseFromString(response,"application/xml");
if(xmlDoc.documentElement.nodeName == "parsererror")
return 'string type';
else
return 'xml type';
}
}