mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
add support to insert raw json
This commit is contained in:
27
cJSON.c
27
cJSON.c
@ -960,6 +960,13 @@ static char *print_value(const cJSON *item, int depth, int fmt, printbuffer *p)
|
||||
case cJSON_Number:
|
||||
out = print_number(item, p);
|
||||
break;
|
||||
case cJSON_Raw:
|
||||
out = ensure(p, strlen(item->valuestring));
|
||||
if (out)
|
||||
{
|
||||
strcpy(out, item->valuestring);
|
||||
}
|
||||
break;
|
||||
case cJSON_String:
|
||||
out = print_string(item, p);
|
||||
break;
|
||||
@ -987,6 +994,9 @@ static char *print_value(const cJSON *item, int depth, int fmt, printbuffer *p)
|
||||
case cJSON_Number:
|
||||
out = print_number(item, 0);
|
||||
break;
|
||||
case cJSON_Raw:
|
||||
out = cJSON_strdup(item->valuestring);
|
||||
break;
|
||||
case cJSON_String:
|
||||
out = print_string(item, 0);
|
||||
break;
|
||||
@ -1947,6 +1957,23 @@ cJSON *cJSON_CreateString(const char *string)
|
||||
return item;
|
||||
}
|
||||
|
||||
extern cJSON *cJSON_CreateRaw(const char *raw)
|
||||
{
|
||||
cJSON *item = cJSON_New_Item();
|
||||
if(item)
|
||||
{
|
||||
item->type = cJSON_Raw;
|
||||
item->valuestring = cJSON_strdup(raw);
|
||||
if(!item->valuestring)
|
||||
{
|
||||
cJSON_Delete(item);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
cJSON *cJSON_CreateArray(void)
|
||||
{
|
||||
cJSON *item = cJSON_New_Item();
|
||||
|
Reference in New Issue
Block a user