RTS API Documentation  1.10.11
switch_json.c
Go to the documentation of this file.
1 #include "switch.h"
2 
4 {
5  va_list ap;
6  char *str;
7  cJSON *item;
8 
9  va_start(ap, fmt);
10  str = switch_vmprintf(fmt, ap);
11  va_end(ap);
12 
13  if (!str) return NULL;
14 
15  item = cJSON_CreateString(str);
16 
17  free(str);
18 
19  return item;
20 }
21 
22 SWITCH_DECLARE(const char *)cJSON_GetObjectCstr(const cJSON *object, const char *string)
23 {
24  cJSON *cj = cJSON_GetObjectItem(object, string);
25 
26  if (!cj || cj->type != cJSON_String || !cj->valuestring) return NULL;
27 
28  return cj->valuestring;
29 }
30 
31 /* For Emacs:
32  * Local Variables:
33  * mode:c
34  * indent-tabs-mode:t
35  * tab-width:4
36  * c-basic-offset:4
37  * End:
38  * For VIM:
39  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
40  */
char * valuestring
Definition: switch_cJSON.h:107
int cJSON_bool fmt
Definition: switch_cJSON.h:150
#define cJSON_String
Definition: switch_cJSON.h:86
const char * cJSON_GetObjectCstr(const cJSON *object, const char *string)
Definition: switch_json.c:22
cJSON * cJSON_CreateStringPrintf(const char *fmt,...)
Definition: switch_json.c:3
Main Library Header.
#define SWITCH_DECLARE(type)
cJSON * item
Definition: switch_cJSON.h:210
int type
Definition: switch_cJSON.h:104
char * switch_vmprintf(const char *zFormat, va_list ap)