We'd love to hear from you! Provide  feedback  to earn a badge today. Take our quick survey
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

can not get json output from custom js library

Received Response
18
Views
5
Comments
edited Feb 21, 2021 12:58PM in Integration 5 comments

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:

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!