Skip to content

Commit

Permalink
Add cJSON_CreateInt function paired with cJSON_SetIntValue
Browse files Browse the repository at this point in the history
Change-Id: Ie9c752c0ba98d77c93d4bf225f1648abf56b3541
  • Loading branch information
xiaoxiang781216 committed Mar 30, 2021
1 parent 324a6ac commit 74657b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,18 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean)
return item;
}

CJSON_PUBLIC(cJSON *) cJSON_CreateInt(int num)
{
cJSON *item = cJSON_New_Item(&global_hooks);
if(item)
{
item->type = cJSON_Number;
cJSON_SetIntValue(item, num);
}

return item;
}

CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num)
{
cJSON *item = cJSON_New_Item(&global_hooks);
Expand Down
1 change: 1 addition & 0 deletions cJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateInt(int num);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
Expand Down

0 comments on commit 74657b7

Please sign in to comment.