Python3 GRPC Protobuf 转换为 JSON 或 Python3 对象

yufei       4 年 前       3816

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)
目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.