Python3 GRPC Protobuf 转换为 JSON 或 Python3 对象

Python3 GRPC Protobuf 转换为 JSON 或 Python3 对象

Python3 调用 GRPC 的时候有时候需要将 Protobuf 调用转换为 JSON 或 Python3 对象,这个操作 google.protobuf 库已经帮我们备好了工具

Protobuf -> Python 对象

from google.protobuf.json_format import MessageToJson

jsonObj = MessageToJson(protobuf_obj)

Protobuf -> Python dict

from google.protobuf.json_format import MessageToDict

dict_obj = MessageToDict(org)
posted @ 2023-02-28 17:56  michaelchengjl  阅读(304)  评论(0编辑  收藏  举报