如何从Google.protobuf提取特定字段(或仅此转换为字符串)
我从API中获得了有关我城市中电车和公共汽车的实时数据,这种类型是:
print(type(feed.entity))
<class 'google.protobuf.pyext._message.RepeatedCompositeContainer'>
看起来像这样(转换为字符串看起来相同):
[id: "4312"
vehicle {
trip {
trip_id: "\"1_740096^K"
schedule_relationship: SCHEDULED
route_id: "488"
}
position {
latitude: 52.335411071777344
longitude: 17.164840698242188
speed: 14.4399995803833
}
current_stop_sequence: 2
timestamp: 1654021682
vehicle {
id: "4312"
label: "488/12"
}
}
, id: "4318"
vehicle {
trip {
trip_id: "\"1_740217^G"
schedule_relationship: SCHEDULED
route_id: "432"
}
position {
latitude: 52.39680862426758
longitude: 16.94964027404785
speed: 0.0
}
current_stop_sequence: 0
current_status: INCOMING_AT
timestamp: 1654021677
vehicle {
id: "4318"
label: "432/8"
}
}
,
我的目的是获取每辆车的ID,Route_ID,纬度和经度(然后)使用熊猫,将此点放入叶叶中)。我想知道什么是从原始格式或字符串中提取此方法的最佳方法。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 protobuf ,然后访问所需的字段。
You can convert the message to dictionary using
MessageToDict
from protobuf, then access the fields that you want.