You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C doesn't support reflection, but we could use struct packing tricks to try and map a JSON object to a user-defined struct.
The main downside would be to organize the fields EXACTLY the same as the JSON. The names wouldn't matter since we can't actually read them.
E.g., we would have to do something like
// this specific packed attribute is GCC specific and may be different// for other compilersstruct __attribute__((__packed__)) person_t
{
char*name;
int32_tage;
};
char*json_string="{\"name\": \"John\", \"age\": 24}";
structperson_tperson;
json_create_struct_from_string(&person, json_string);
person.name; // Johnperson.age; // 24
The text was updated successfully, but these errors were encountered:
C doesn't support reflection, but we could use struct packing tricks to try and map a JSON object to a user-defined struct.
The main downside would be to organize the fields EXACTLY the same as the JSON. The names wouldn't matter since we can't actually read them.
E.g., we would have to do something like
The text was updated successfully, but these errors were encountered: