Add getNumberValue function

* Add GetNumberValue function and testcase

Co-authored-by: Alan Wang <wp_scut@163.com>
This commit is contained in:
Sang-Heon Jeon
2020-04-02 18:06:56 +09:00
committed by Alanscut
parent 983bb2b4d6
commit 97cf1d84e4
3 changed files with 31 additions and 4 deletions

16
cJSON.c
View File

@ -79,14 +79,26 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
return (const char*) (global_error.json + global_error.position);
}
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) {
if (!cJSON_IsString(item)) {
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item)
{
if (!cJSON_IsString(item))
{
return NULL;
}
return item->valuestring;
}
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item)
{
if (!cJSON_IsNumber(item))
{
return 0.0/0.0;
}
return item->valuedouble;
}
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 12)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.