python pb与json互转

(1)  test.proto文件:
                 message  test {

       optional int32 a1 =1;

       optional int32 a2 =2;

     }

 (2)python 文件:

     from google.protobuf import json_format

     json_obj='{"a1":1,"a2":2}'

     // json to pb

     request = json_format.Parse(json_obj,test_pb2.test())

     //pb to json  

     json_result = json_format.MessageToJson(request)

猜你喜欢

转载自blog.csdn.net/zgb40302/article/details/89350997
今日推荐