#include <stdio.h>
#include <assert.h>
#include <strings.h>
#include "vn_json.h"

// #define VN_JSON_FALSE  0
// #define VN_JSON_TRUE   1
// #define VN_JSON_NULL   2
// #define VN_JSON_NUMBER 3
// #define VN_JSON_STRING 4
// #define VN_JSON_ARRAY  5
// #define VN_JSON_OBJECT 6
	
int main(int argc, char *argv[])
{
    FILE *fh = fopen("test.json", "r");
    char *data = new char[65536];

    bzero(data, 65536);

    fread(data, 65535, 1, fh);
    fclose(fh);
    
    vn_json_t *js = vn_json_parse(data);
    assert(js);
    
    vn_json_t *list = vn_json_get_object_item(js, "list");
    assert(list && vn_json_get_type(list) == VN_JSON_ARRAY);

    printf("array size: %d\n", vn_json_get_array_size(list));
//    while (

    for (vn_json_t *obj = vn_json_child(list); obj != 0; obj = vn_json_next(obj))
    {
        printf("child type: %c\n", "FTZNSAO"[vn_json_get_type(obj)]);
//         vn_json_t *attr = vn_json_get_object_item(obj, "attributes");
//         assert(attr && vn_json_get_type(attr) == VN_JSON_OBJECT);

        for (vn_json_t *a = vn_json_child(obj); a != 0; a = vn_json_next(a))
        {
//            printf("type: %c\n", "FTZNSAO"[vn_json_get_type(a)]);
//            if (vn_json_get_type(attr) == VN_JSON_STRING)
            {
                printf("%s:%s\n", vn_json_get_name(a), vn_json_get_string(a));
            }

         }

// //	{cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}

//         // {
//         //     vn_json_t *a = vn_json_get_object_item(attr, "DEVICETYPE");
//         //     printf("%s\n",  vn_json_get_string(a) );
//         //     exit(1);
//         // }

//         printf("========================================\n");
//         printf("array size: %d\n", vn_json_get_array_size(attr));

//         for (vn_json_t *a = vn_json_child(attr); a != 0; a = vn_json_next(a))
//         {
// //            printf("type: %c\n", "FTZNSAO"[vn_json_get_type(a)]);
// //            if (vn_json_get_type(attr) == VN_JSON_STRING)
//             {
//                 printf("%s:%s\n", vn_json_get_name(a), vn_json_get_string(a));
//             }

//         }
//         printf("========================================\n");
 
//        exit(1);
        
    }


    // vn_json_t *item = vn_json_child(list);
    // assert(item && vn_json_get_type(item) == VN_JSON_OBJECT);    
    // printf("child type: %c\n", "FTZNSAO"[vn_json_get_type(item)]);


    // item = vn_json_next(item);
    // assert(item);    
    // printf("next type: %c\n", "FTZNSAO"[vn_json_get_type(item)]);








    // item = vn_json_next(list);
    // assert(item);    
    // printf("next type: %c\n", "FTZNSAO"[vn_json_get_type(item)]);


//    for (int i = 0


    delete[] data;

    return 0;
}
