Voce should first know exactly what the "JSON format is"...
value: "1",
should be written as "value": "1",
- JSON is a format, there is no
;
- what you wrote is a
array
, should be built in []
that is to say [ { "value":"1","descricao":"2"}, ... ]
use an Online Parser to see if the syntax is correct, for example: http://json.parser.online.fr/
the correct text in your file should be written as:
[
{
"value": "1",
"descricao": "1"
},
{
"value": "2",
"descricao": "2"
},
{
"value": "3",
"descricao": "3"
}
]
Just to add a little more information about the format, the variables have to be delimited by double quote "
, only the values is that...
"value": "3"
causes the value
has the value of a string with content 3
"value": 3
causes the value
has the value of a number with content 3
, that is, in the case only his example, and imagining that the object has the variable data
:
the result of data[0].value + data[1].value
will be of 12
and not 3
in place of
alert(data);
putsconsole.log(data);
and see what returns.– henriquedpereira
nothing returns either.
– Daniel
By pressing F12 in the browser you enter the toolbar where you can go in the browser console to check for errors.
– Joao Paulo
there is no mistake.
– Daniel