huangcm
2025-07-01 676035278781360996553c427a12bf358249ebf7
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
/*
 * JSON parser - test program
 * Copyright (c) 2019, Jouni Malinen <j@w1.fi>
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */
 
#include "utils/includes.h"
#include "utils/os.h"
#include "utils/json.h"
 
 
int main(int argc, char *argv[])
{
   char *buf;
   size_t len;
   struct json_token *root;
 
   if (argc < 2)
       return -1;
 
   buf = os_readfile(argv[1], &len);
   if (!buf)
       return -1;
 
   root = json_parse(buf, len);
   os_free(buf);
   if (root) {
       size_t buflen = 10000;
 
       buf = os_zalloc(buflen);
       if (buf) {
           json_print_tree(root, buf, buflen);
           printf("%s\n", buf);
           os_free(buf);
       }
       json_free(root);
   } else {
       printf("JSON parsing failed\n");
   }
 
   return 0;
}