cJSON provides a function
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string)
I created a test function
#include "cJSON.h"
const char *jsonstring = "{\"b\": {\"b1\":\"2b\"}}";
void jsontest(void)
{
cJSON *cJSON_data = cJSON_Parse(jsonstring);
char *buffer = cJSON_Print(cJSON_data);
printf("JSON_String:%s\r\n",buffer);
cJSON *bfound = cJSON_GetObjectItemCaseSensitive(cJSON_data,"b1");
printf("bfound: 0x%08x\n",(char*)bfound);
free(cJSON_data);
free(buffer);
}
The output is
JSON_String:{
"b": {
"b1": "2b"
}
}
bfound: 0x00000000
`
If I use this string,
const char *jsonteststr1 = "{\"a\":\"1\",\"b\":\"2\",\"c\":\"3\"}";
GetObjectItemCaseSensitive()
will find "a", "b", and "c".
GetObjectItemCaseSensitive()
does not seem to recurse.
Am I doing something wrong? Do I not understand how to use GetObjectItem()
?
I am using version 1.7.12