我从Firebase实时数据库收到JSON数据 -
这是Json:
var data={
"07:08:2017_16:57:48": {
"fech": "07:08:2017",
"hor": "16:57:48",
"lat": -41.1515438,
"lng": -71.4083591,
"telef": ""
},
"07:08:2017_16:58:04": {
"fech": "07:08:2017",
"hor": "16:58:04",
"lat": -41.1515438,
"lng": -71.4083591,
"telef": "2944895972"
},
"07:08:2017_16:58:05": {
"fech": "07:08:2017",
"hor": "16:58:05",
"lat": -41.1515438,
"lng": -71.4083591,
"telef": "2944895972"
}
}
我需要lat值,但我不明白如何在这种情况下使用索引
我试过了:
var dataj= JSON.parse(data);
var latitud1= dataj[1];
任何帮助?
答案 0 :(得分:1)
如果您确实拥有该JavaScript结构,则此代码将打印纬度值:
Object.keys(data).forEach(function(key) {
console.log(data[key].lat);
});
Runnable片段:
var data = {
"07:08:2017_16:57:48": {
"fech": "07:08:2017",
"hor": "16:57:48",
"lat": -41.1515438,
"lng": -71.4083591,
"telef": ""
},
"07:08:2017_16:58:04": {
"fech": "07:08:2017",
"hor": "16:58:04",
"lat": -41.1515438,
"lng": -71.4083591,
"telef": "2944895972"
},
"07:08:2017_16:58:05": {
"fech": "07:08:2017",
"hor": "16:58:05",
"lat": -41.1515438,
"lng": -71.4083591,
"telef": "2944895972"
}
};
Object.keys(data).forEach(function(key) {
console.log(data[key].lat);
});