Java
http://code.google.com/p/protobuf-java-format/
maven配置
-
<dependency> -
<groupId>com.googlecode.protobuf-java-format</groupId> -
<artifactId>protobuf-java-format</artifactId> -
<version>1.2</version> -
</dependency>
从protobuf转json
-
Message someProto = SomeProto.getDefaultInstance(); -
String jsonFormat = JsonFormat.printToString(someProto);
从json转protobuf
-
Message.Builder builder = SomeProto.newBuilder(); -
String jsonFormat = load json from source; -
JsonFormat.merge(jsonFormat, builder);
本文介绍了如何使用protobuf-java-format库在Java中实现Protobuf消息与JSON格式之间的转换。通过简单的代码示例,展示了从Protobuf转JSON及从JSON还原为Protobuf的过程。
293

被折叠的 条评论
为什么被折叠?



