-1
Gentlemen, excuse my ignorance but how can I read a JSON key that starts in number, example:
"1x2": {
"outright": false,
"interwetten": {
"odds": {
"1": 6.4,
"2": 1.55,
"X": 3.95
},
"bookmaker": true,
"exchange": false,
"name": "Interwetten"
},
"bwin": {
"odds": {
"1": 6.5,
"2": 1.5,
"X": 3.8
},
"bookmaker": true,
"exchange": false,
"name": "bwin"
},
.....
I’m doing the reading as follows:
$.getJSON("MEUJSON", function(retorno){
.each(retorno, function (i) {
// console.log(retorno);
var data = retorno[i].event.start_time;
$('.tabela').append(retorno[i].event.away);
$.each(retorno[i].sites, function(a) {
//AQUI SERIA A LEITURA DA CHAVE
console.log(retorno[i].sites[a].\`1x2`\);
})
})
})
Thanks in advance!
Got it, in case my JSON it has other keys, and it’s inside a $.each, I’m doing like this: $. getJSON("MEUJSON", Function(return){ $.each(return, Function (i) { // console.log(return); var data = return[i].event.start_time; $('. table'). append(return[i].event.away); $.each(return[i]. sites, Function(a) { //HERE WOULD BE THE READING OF THE KEY console.log(return[i]. sites[a]. `1x2`); }) }) })
– Cristiano Facirolli
Try it this way
console.log(retorno[i].sites[a]['1x2']
replacing that partretorno[i].sites[a].`1x2
The difference is that you do not access with the . and yes with the clasps []– Robson Silva
Good morning, I tried and did not roll, it returns me -> Undefined.
– Cristiano Facirolli
Good morning, so it’s because inside the object
retorno[i].sites[a]
there is no direct key called '1x2', if you can send the full structure of json, at least this part of the access tosite
, because I think this object is not directly on site. If you can send the complete structure of site, it will be easier to help.– Robson Silva