mirror of
https://github.com/DaveGamble/cJSON.git
synced 2026-08-12 12:37:47 +00:00
Add getNumberValue function
* Add GetNumberValue function and testcase Co-authored-by: Alan Wang <[email protected]>
This commit is contained in:
committed by
Alanscut
co-authored by
Alan Wang
parent
983bb2b4d6
commit
97cf1d84e4
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user