Skip to content

Want to write a class member variable and a struct variable ( this structure is inside the class) to the json file #1145

@quicksilver345

Description

@quicksilver345

I have a class and inside that class i have a struct, now i want to write the class variable "name" and the structure member "a" in the json file but i am not able to do so, can you please help me with the problem. :-

Code snipet ->

class ABC
            {
            public:
                struct ex
                {
                public:
                    int a;
                };
                static void registerclass()
                {
                    ClassMetaInfo<ABC>::registerMember("name", &ABC::name);
                    ClassMetaInfo<ex>::registerMember("int a ", &ex::a);
                }
                std::string name;
                ex var = { };
                
            };

            ABC::registerclass();
            ABC p;
           p.name = "JOHN";
            json j = ClassMetaInfo<ABC>::deserialize(p);

json file output :-

{
    "name": "JOHN"
}

By the above code i am getting the class variable "name" written in the json file but cannot see the structure variable "a" in the json file.

I have tried to put the registerclass() method inside the structure also but still i am not getting the stucture variable "a" written in my json file

(I want to write both the class variable and the structure variable in the json file, as per the above example i am expecting something like :-

{
    "name": "JOHN"
    " int a" : 32 
}

to be the json output
)

Can you please help me regarding the issue
(Compiling on a windows machine in visual studio 2017)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions