将 JSON 字符串保存在动态全局字典中,python
我是Python新手。我有多个 JSON 消息通过 MQTT 代理发送到 python 应用程序,具有相同的键但不同的值。我想做的是根据某个值将 JSON 字符串存储在动态全局字典中,并且它将被每个具有相同值的新消息替换。 然后我可以从任何函数获取这些值。
例如:如果我有以下消息,
{'timestamp': 1646682501888, 'description': 'address', 'postal': 'AAA', 'city': 'ABC'}
我想在第一条记录中保存该消息的记录,其中城市为 ABC,邮政为 AAA,如果城市为“EFG”,邮政为“ZZZ”,则将其存储在第二条记录中记录, 每当有新消息到来时,如果它具有相同的城市和邮政地址,它就会更新完整的消息。我想知道如何从任何函数访问字典中的值。 谢谢
I am new to python. I have multiple JSON messages coming to the python application trough MQTT broker with the same keys but different values. what I am trying to do is to store the JSON string on a dynamic global dictionary according to a certain value and it will be replaced with each new messages has that same value.
then I can reach these values from any functions.
for example: if I have the following message
{'timestamp': 1646682501888, 'description': 'address', 'postal': 'AAA', 'city': 'ABC'}
I want to save a record of this message when city is ABC and postal is AAA in the first record, and if the city is "EFG" and postal is "ZZZ" store it in a second record,
than whenever a new message is coming it will update the full message if it has the same city and postal. please I want to know how to access values in the dictionary from any function.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论