C++ Protobuf to/from JSON conversion [closed]

一个人想着一个人 提交于 2019-12-03 08:44:37

问题


Is anyone familiar with a stable C++ solution (library, code snippet etc.) which converts protobuf messages to/from JSON?


回答1:


This one is better IMO: https://github.com/shramov/json2pb

it does conversion in both directions and handles extensions




回答2:


pbjson is another one, which built on rapidjson, maybe faster.




回答3:


I've made a bootstrap implementation of a JSON parser for protobuf generated types, using the its reflection mechanism, and adapting the parse I've made previously for CORBA IDL generated types.

You can find it at http://corbasim.googlecode.com/svn/trunk/protobuf2json_exported.zip

By this way for each protobuf defined message, you will be able to parse its instances by doing:

Foo foo;

const std::string json_foo = "{\"text\": \"Hello world\"}";

protobuf2json::json::parse(foo, json_foo);

It's just an initial implementation, and it just support string fields, but it's easy to implement all kind of fields.




回答4:


pb2json is another C++ library that can do this.



来源:https://stackoverflow.com/questions/7007876/c-protobuf-to-from-json-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!