When using my web application, the Web API responds with the following JSON object:
[
{
"templateID":1,
"template":"{\r\n \"Body\": \"sample date hete hee. Name\"\r\n}"
},
{
"templateID":2,
"template":"{ \"Body\": \"you soon.\" }"
}
]
My task is to extract the Body
value from each JSON node by providing the corresponding templateID
. The challenge lies in the presence of \r\n
characters within the JSON data. Regardless, I must retrieve the Body value for each node. For instance, if I input 1, I should receive sample date hete hee. Name
, and for 2, I require you soon.
. How can this be achieved?
I have attempted a solution, but it does not seem to work as expected.
var data2 = [
{
"templateID":1,
"template":"{\r\n \"Body\": \"sample date hete hee. Name\"\r\n}"
},
{
"templateID":2,
"template":"{ \"Body\": \"you soon.\" }"
}
]
function usersBasedOnIDs(isShow,field){
var filtered=data2.filter(function(item){
return item[field] == isShow;
});
console.log(filtered);
}
usersBasedOnIDs(1,'templateID');