This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19227|Reply: 0

[Source] .net/c# Protocol Buffer to json data

[Copy link]
Posted on 5/19/2017 2:08:04 PM | | | |


Because the data conversion often throws exceptions in the debugging stage, and I don't know what the original data is, because of some factors, it is not easy to debug, I need to record the original data

The data transmission format adopts the Google Protocol Buffer protocol, at the beginning, the data object is an object automatically generated by Protocol Buffer, I want to use our commonly used json.net to convert the object into a json string and write it to the log, the code is as follows:



The logging input is as follows:

INFO  2017-05-19 13:12:07,733 [loginfo] Json:{"message":" CgR0ZXN0EOiWFBoGcmVyd3F3IgUzMjMzMioGMzIzMjMyMgU0MzQ0MzoHNDQzMzQ0M0IGMzIzMjMySgYyMzMyMzJSBjMyMzIzM1oGMzIzMjMyYISU8AVoIHAgeNqJ6Do=","initialized":true}
INFO  2017-05-19 13:12:07,735 [loginfo] Json:{"message":" CgR0ZXN0EOiWFBoGcmVyd3F3IgUzMjMzMioGMzIzMjMyMgU0MzQ0MzoHNDQzMzQ0M0IGMzIzMjMySgYyMzMyMzJSBjMyMzIzM1oGMzIzMjMyYISU8AVoIHAgeNqJ6Do=","initialized":true}
INFO  2017-05-19 13:12:07,737 [loginfo] Json:{"message":" CgR0ZXN0EOiWFBoGcmVyd3F3IgUzMjMzMioGMzIzMjMyMgU0MzQ0MzoHNDQzMzQ0M0IGMzIzMjMySgYyMzMyMzJSBjMyMzIzM1oGMzIzMjMyYISU8AVoIHAgeNqJ6Do=","initialized":true}
INFO  2017-05-19 13:12:07,739 [loginfo] Json:{"message":" CgR0ZXN0EOiWFBoGcmVyd3F3IgUzMjMzMioGMzIzMjMyMgU0MzQ0MzoHNDQzMzQ0M0IGMzIzMjMySgYyMzMyMzJSBjMyMzIzM1oGMzIzMjMyYISU8AVoIHAgeNqJ6Do=","initialized":true}
INFO  2017-05-19 13:12:07,741 [loginfo] Json:{"message":" CgR0ZXN0EOiWFBoGcmVyd3F3IgUzMjMzMioGMzIzMjMyMgU0MzQ0MzoHNDQzMzQ0M0IGMzIzMjMySgYyMzMyMzJSBjMyMzIzM1oGMzIzMjMyYISU8AVoIHAgeNqJ6Do=","initialized":true}
INFO  2017-05-19 13:12:07,743 [loginfo] Json:{"message":" CgR0ZXN0EOiWFBoGcmVyd3F3IgUzMjMzMioGMzIzMjMyMgU0MzQ0MzoHNDQzMzQ0M0IGMzIzMjMySgYyMzMyMzJSBjMyMzIzM1oGMzIzMjMyYISU8AVoIHAgeNqJ6Do=","initialized":true}
Obviously, this is not what we want。。。。。 What to do???

Intuition told me :Google.ProtocolBuffers.Serialization.dll this should be converted to json, haha, tried it and sure enough, the code is as follows:







Previous:nhibernate cannot successfully create a table structure in a MySQL database
Next:HP Ghost Windows7 32-bit & 64-bit Ultimate v201705
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com