0
I’m starting to mess with JSON and Javascript and have the following AJAX:
$.ajax({
url: 'https://...',
type: 'POST',
dataType: 'json',
data: 'inpnomeRequisitante=' + 'XXXXXXXXXX',
success: function (data) {
var fluxosAndamento = "";
var fluxosSolicitadosAnoCorrente = "";
var valor = 0;
$.each(data.success, function (i, item) {}});
This AJAX returns the values exactly like this:
{
"success": [
{
"fields": {
"Valor": "22,33",
}
},
{
"fields": {
"Valor": "146,33",
}
}
],
"cache": false,
"datasource": 2166,
"runtime": 63,
"bytes": 2369
}
I would like to know how it is possible to sum all the returned values of data.success[i].fields.Valor
, as in this example: 22,33 + 146,33 + VALOR XXXX
(if it has more values)... And how can I replace the ",
" to the ".
" at each of these values within the $each so that they can be summed since Javascript does not accept "10,00
" and yes "10.00
".
Your JSON is not valid. Are you sure that’s how it is?
– Woss
Yeah, I didn’t put it here at a url or the date I’m going through. However, it returns the data exactly as it is there: "Value": "146,33", "Value": "22,33",
– Gabi M
So if it is exactly as it is there, it is not a valid JSON, there is no way to analyze it with JS. It seems that there is a wrong brackets on line 13 that perhaps should not exist.
– Woss
Sorry @Andersoncarloswoss! Exactly, this bracket does not exist there. You would know how to take the value of each date.?
– Gabi M
Please edit the question by adding valid JSON so we can help you more easily.
– Luiz Felipe