Reputation:
I've written a composite adapter which makes multiple webservice calls and returns JSON object as response which is stored in variables x & y respectively. Now I am supposed to concatenate x and y since they conform to the same JSON structure and return as a single object, say "z" to my client application which calls the adapter. But I'm getting an Error saying "cannot find function concat in object". Do you have some clue here ?
Ex. var z = x.concat(y); return z;
Upvotes: 0
Views: 252
Reputation: 3166
JSON object doesn't have a concat function. You need to iterate object fields and add them to response. e.g. if you have answ1, answ2 and answ3 this might looks similar to
function extendObj(dstObj, srcObj){
for (var key in srcObj){
if(srcObj.hasOwnProperty(key)) dstObj[key] = srcObj[key];
}
}
after that you can use this function to concat objects
var response = {};
extendObj(response, answ1);
extendObj(response, answ2);
extendObj(response, answ3);
return response;
Upvotes: 1