Reputation: 67
I'm using axios to call APIs I received an API without patterns, and the return is:
{
"pedidos": [
{
"cnpj": "09922334480001",
"nr-pedido": "1234567",
"os-cliente": "811",
"data-entrada": "2020-08-03",
"previsao-entrega": "2020-09-28",
"status": "Em processo"
}
]
}
When i parse JSON i use:
result.data.pedidos[0].status;
but when i have "-" in fields how can i call? When i use:
result.data.pedidos[0].previsao-entrega
the error is returned.
Anyone can help me?
Upvotes: 0
Views: 26
Reputation: 1781
Like so:
result.data.pedidos[0]["previsao-entrega"]
See here:
https://stackoverflow.com/a/13869651/12485722
Upvotes: 1
Reputation: 70143
For keys with "-"
and other characters that won't work with dot (.
) notation, use the bracket ([
and ]
) notation instead, and enclose the key in quotation marks to make it a string:
result.data.pedidos[0]["data-entrada"]
Upvotes: 2