-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.c
62 lines (51 loc) · 1.35 KB
/
test1.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "myjson.h"
int main(int argc, char **argv)
{
Object *json;
String *strjson;
int res;
printf("[TEST01]------------------------\n");
res = loads("{\"name\":\"yefeng\"}\n", &json);
printf("res = %d\n", res);
Object_debug(json);
printf("\n");
Object_free(json);
printf("[TEST02]------------------------\n");
FILE *in_f;
if (argc > 1)
{
if ((in_f = fopen(argv[1], "r")) == NULL)
{
perror(argv[1]);
exit(1);
}
}
else
{
in_f = stdin;
}
res = load(in_f, &json);
printf("res = %d\n", res);
// Object_debug(json); printf("\n");
strjson = (String *)new_string_empty(1000);
res = dumps(json, strjson);
printf("dump res= %d\n", res);
if (res == 0) {
printf("json decode SUCCESS: %s\n", strjson->value);
}
Object_free(json);
Object_free((Object *)strjson);
printf("[TEST03]------------------------\n");
res = loads("{'id\':\"1234567890\"}\n", &json);
printf("res = %d\n", res);
// Object_debug(json);
strjson = (String *)new_string_empty(1000);
res = dumps(json, strjson);
printf("dump res= %d\n", res);
if (res == 0) {
printf("json decode SUCCESS: %s\n", strjson->value);
}
Object_free(json);
Object_free((Object *)strjson);
return 0;
}