I need to create a function that works on all the parameters of a JSON object to look up data fields and manipulate them. Basically the object I can receive is something like:
{
idPedido:1,
dataCriado: "/Date(1454637600000-0200)/",
cliente: "Nome do Cliente",
pagamento:[
{
idPgto:1,
valor: 100.00,
tipoPgto:"dinheiro",
dataVenc:"/Date(1454637600000-0200)/"
},
{
idPgto:2,
valor: 100.00,
tipoPgto:"cartão",
dataVenc:"/Date(1454657600000-0200)/"
}
],
produtos:[
{
idProduto:1,
descricao:"bola",
valor:200.00
}
]
}
My problem is that there may be numerous variants that contain this date format (unfortunately the webservice I'm being forced to work on just sends me this way ...)
I need to know how I can do a function that I can apply to all parameters that exist within JSON, regardless of its level. today the function I'm using is this:
function corrigeData(d) {
if(d.indexOf('Date('){
d = d.replace(/\/Date\(/g, '').replace(/\)\//g, '');
d = new Date(d);
};
return d;
}
The problem is that I have to pick up and know where I'll probably find the date field. But if by chance you change something in my backend scope, I'll have to go back and implement that as well, which is unnecessary with a recursive function.
Any suggestions?