简体   繁体   中英

C++ reflection and to/from key value pair (like json)

I found this answer to kind of do reflection in C++: https://stackoverflow.com/a/11748131/5507357

However, I would like to 'expand' this to do 'deserialization'. So for example, I have a json Person object

{ 
    "Person": 
    { 
        "name": "Tom",
        "age": 82
    }
}

Or an ini file, or xml. How can I create a Person struct with these values with this reflection? The code does not have to 'detect' it is a Person object, it is all about the members.

I would advice you to look at Google Protocol Buffers . In C++ reflections are supported and json export. In other languages json import is also supported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM