从一个 API 我得到了这些类型的响应。我需要获取单个实体的纬度、经度。如何使用 javascript (node js) 过滤这些数据。
header {
gtfs_realtime_version: "1.0"
incrementality: FULL_DATASET
timestamp: 1501132018
}
entity {
id: "1"
vehicle {
trip {
trip_id: "141.180717.42.1145"
schedule_relationship: SCHEDULED
route_id: "4T.C.141"
}
position {
latitude: -29.77179
longitude: 151.11717
bearing: 90.00001
}
timestamp: 1501131987
congestion_level: UNKNOWN_CONGESTION_LEVEL
stop_id: "23604"
vehicle {
id: "141"
label: "11:45am (141) Grafton City - Moree Town"
}
}
}
entity {
id: "2"
vehicle {
trip {
trip_id: "511.160717.90.1416"
schedule_relationship: SCHEDULED
route_id: "4T.C.511"
}
position {
latitude: -32.09544
longitude: 148.06787
bearing: 313.0
}
timestamp: 1501131974
congestion_level: UNKNOWN_CONGESTION_LEVEL
stop_id: "28211"
vehicle {
id: "511"
label: "02:16pm (511) Dubbo - Bourke"
}
}
}
所有这些数据都是交通API。如果它是 JSON 格式,那么我们可以使用 foreach 并使用它的索引来获取它。