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

社会主义新天地 提交于 2019-12-02 22:45:21

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

it does conversion in both directions and handles extensions

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.

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

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

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