can not get json output from custom js library
Content
I am trying to convert to xml response to JSON format and return it as json format but oic js function only support string output. Consuqently we are getting this response:
"[{
\"ORDER_NO\":xxxx,
\"FULFILL_LINE_ID\":xxxxx,
\"LINE_NUMBER\":\"1-1:\"
}]"
but we want to JSON format like this
[{
"ORDER_NO":xxxx,
"FULFILL_LINE_ID":xxxxx,
"LINE_NUMBER":"1-1:"
}]
how can we achive that?
I upload SS of mapping response, oic export js code for convertion
Code Snippet
function base64Decode(xml) { // Create the return object //xml=xml.replace('\\n',''); //xml=xml.replace('\\"','"'); var response = []; var pos=xml.indexOf('<G_1>'); var i=0; while(pos!=-1) { xml=xml.substr(pos+5); xml=xml.substr(xml.indexOf('<')); var obj={},key='',value=''; while(xml.substr(0,6)!='</G_1>') { key=xml.slice(1,xml.indexOf('>')); xml=xml.substr(xml.indexOf('>')+1); value=xml.slice(0,xml.indexOf('<')); xml=xml.substr(xml.indexOf('>')+1); xml=xml.substr(xml.indexOf('<')); i++; //console.log(xml.substr(0,6)); if(/^-?[\d.]+(?:e-?\d+)?$/.test(value)) obj[key]=Number(value); else obj[key]=value; } response.push(obj); pos=xml.indexOf('<G_1>'); } var obj=JSON.stringify(response); return obj; };
Tagged:
0