影落离风

The shadow falls away from the wind

0%

json与protobuf对象互转

步骤

  1. 导入protobuf-java-format包

    1
    2
    3
    4
    5
    <dependency>
    <groupId>com.googlecode.protobuf-java-format</groupId>
    <artifactId>protobuf-java-format</artifactId>
    <version>1.4</version>
    </dependency>
  2. 主要代码

    1
    2
    3
    4
    5
    6
    7
    8
    JsonFormat jsonFormat = new JsonFormat();
    // protobuf转json
    System.out.println(jsonFormat.printToString(request_2_0));

    AiQiYV215Rta.RTARequest_2_0.Builder builder = AiQiYV215Rta.RTARequest_2_0.newBuilder();
    // json转protobuf对象
    jsonFormat.merge(IoUtil.toUtf8Stream(json), builder);
    System.out.println(builder.getIdfaMd5());

代码

  1. 代码示例

工具

  1. 在线JSON-to-Proto