-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_ez.h
47 lines (42 loc) · 997 Bytes
/
json_ez.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef JSON_EZ_H
#define JSON_EZ_H
#include "thirdparty/json.h"
struct json_value_s *get_object_key_v(struct json_object_s *obj, char *key)
{
for (struct json_object_element_s *oe = obj->start; oe != NULL; oe = oe->next)
{
if (0 == strcmp(oe->name->string, key))
{
return oe->value;
}
}
return NULL;
}
struct json_array_s *get_object_key_as_array(struct json_object_s *obj, char *key)
{
struct json_value_s *o = get_object_key_v(obj, key);
if (o != NULL)
{
return json_value_as_array(o);
}
return NULL;
}
struct json_object_s *get_object_key_as_object(struct json_object_s *obj, char *key)
{
struct json_value_s *o = get_object_key_v(obj, key);
if (o != NULL)
{
return json_value_as_object(o);
}
return NULL;
}
struct json_string_s *get_object_key_as_string(struct json_object_s *obj, char *key)
{
struct json_value_s *o = get_object_key_v(obj, key);
if (o != NULL)
{
return json_value_as_string(o);
}
return NULL;
}
#endif