protobuf与json互相转换,protobuf输出字符串
2017-05-27 11:33
471 查看
protobuf与json互相转换,protobuf输出字符串
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
从json转protobuf
https://github.com/shramov/json2pb
---------------------------------------------------------------------------
Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
Fork from http://code.google.com/p/protobuf-java-format
Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
##Example For XML output, use XmlFormat
For XML input, use XmlFormat
For Json output, use JsonFormat
For Json input, use JsonFormat
For HTML output, use HtmlFormat
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 document from a source_; JsonFormat.merge(jsonFormat, builder);
C++
https://github.com/shramov/json2pb---------------------------------------------------------------------------
Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
Fork from http://code.google.com/p/protobuf-java-format
Description
Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.##Example For XML output, use XmlFormat
Message someProto = SomeProto.getDefaultInstance(); String xmlFormat = XmlFormat.printToString(someProto);
For XML input, use XmlFormat
Message.Builder builder = SomeProto.newBuilder(); String xmlFormat = _load xml document from a source_; XmlFormat.merge(xmlFormat, builder);
For Json output, use JsonFormat
Message someProto = SomeProto.getDefaultInstance(); String jsonFormat = JsonFormat.printToString(someProto);
For Json input, use JsonFormat
Message.Builder builder = SomeProto.newBuilder(); String jsonFormat = _load json document from a source_; JsonFormat.merge(jsonFormat, builder);
For HTML output, use HtmlFormat
Message someProto = SomeProto.getDefaultInstance(); String htmlFormat = HtmlFormat.printToString(someProto);
相关文章推荐
- protobuf与json互相转换
- protobuf与json互相转换
- protobuf与json互相转换
- 浅析Js(Jquery)中,字符串与JSON格式互相转换的示例(直接运行实例)
- json字符串和java对象的互相转换
- c++使用Protobuf Message转Json字符串(Json库使用Json cpp)
- JSON 字符串 与 java 对象之间互相转换
- 在Python标准库的json包中,提供了JSONEncoder和JSONDecoder两个类来实现Json字符串和dict类型数据的互相转换。
- json字符串与java对象互相转换
- Java中对象的list与JSON格式字符串的互相转换
- JSON与字符串互相转换的几种方法
- JSON 字符串 与 java 对象之间互相转换
- json和字符串/数组/集合的互相转换の神操作总结
- JSON对象和字符串的互相转换
- json、对象、字符串互相转换
- 在Js(Jquery)中,字符串与JSON格式互相转换的示例(直接运行例子)
- 参照protobuf,将json数据转换成二进制在网络中传输。
- C#中Dynamic与Json字符串的互相转换
- JSON 字符串 互相转换
- json字符串转换为xml格式输出