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
This is more of a question than issue but can't find a better way to ask it...
I have a bit of code that parses json to create some objects. Among the data being parsed are fields that can take int, but in the codebase there are specific constants that are used for these fields. Now what I'd like to do is to have the label of the constant inside JSON instead of it's integer value.
A simple example is with an enum:
typedef enum { title = 0, heading, normal} textSize;
I can parse this manually with:
int getJsonTextSizeEnum(cJSON * json, const char* label, int defaultValue ){
cJSON * elem = cJSON_GetObjectItemCaseSensitive(json, label);
if ( elem == NULL ) return defaultValue;
if ( cJSON_IsString(elem) ) {
if ( strcmp("title", elem->valuestring) == 0 ) return title;
if ( strcmp("heading", elem->valuestring) == 0 ) return heading;
if ( strcmp("normal", elem->valuestring) == 0 ) return normal;
} else{
return getJsonInt(json, label, defaultValue);
}
return defaultValue;
}
This makes for usable and readable json at the expense of a bit extra code.
But what happens when I have 100s of values to translate? Say, for example I want to specify the icon from fontawesome. Ideally, I'd like to have meaningful icon name in json (ICON_FA_FLASK), not an unintelligible codepoint ("\xef\x83\x83") - without hundreds of lines of code.
Any suggestions?
The text was updated successfully, but these errors were encountered:
This is more of a question than issue but can't find a better way to ask it...
I have a bit of code that parses json to create some objects. Among the data being parsed are fields that can take int, but in the codebase there are specific constants that are used for these fields. Now what I'd like to do is to have the label of the constant inside JSON instead of it's integer value.
A simple example is with an enum:
typedef enum { title = 0, heading, normal} textSize;
I can parse this manually with:
This makes for usable and readable json at the expense of a bit extra code.
But what happens when I have 100s of values to translate? Say, for example I want to specify the icon from fontawesome. Ideally, I'd like to have meaningful icon name in json (
ICON_FA_FLASK
), not an unintelligible codepoint ("\xef\x83\x83"
) - without hundreds of lines of code.Any suggestions?
The text was updated successfully, but these errors were encountered: