首页 > 解决方案 > 在python中查找字节数组子字符串时获取最大值

问题描述

我正在使用python3。以下是我的示例数据 b'{"receivedTimestamp":1604484102747,"application":"MMT","messageType":"BusEvent","utcTimestamp":1604484102711,"data":[{"id":56476901531}]}{"receivedTimestamp":1604484102748,"application":"MMT","messageType":"BusEvent","utcTimestamp":1604484102711,"data":[{"id":56476901532}]}'

在python中,我猜上面的数据被视为字节数组

数据说明 如果我们观察到有 2 条 json 消息,每个 json 消息标签都以receivedTimestamp开头

我需要的 ? 我需要找到这两条消息的最大时间戳,它应该返回值 1604484102748,因为它更大。

我正在努力解析这条消息。请求任何人解析这些数据或指出正确的方向来构建代码并在 python 中获取预期值。

提前感谢

标签: pythonjsonstringtransformationreal-time-data

解决方案


tmp = str(my_json)
i = tmp.rfind('receivedTimestamp') # index of last appearance receivedTimestamp
i = i-2 #index between jsons
first_json = json.loads(tmp[2:i])
second_json = json.loads(tmp[i:-1])


推荐阅读