sheredom / json.h

🗄️ single header json parser for C and C++
The Unlicense
698 stars 77 forks source link

Iterate over array linked list #75

Closed MasterCna closed 3 years ago

MasterCna commented 3 years ago

I've tried to use the lib for my Windows Driver json parsing requirements. Everything is fine and working but I can't figure out how I can iterate through array object to get all values. My Json: {"app_blocks":["firefox","cmd","chrome"]}

Here is my code: ` struct json_value_s* root = json_parse(buffer, strlen(buffer));

struct json_object_s* object = (struct json_object_s*)root->payload;

struct json_object_element_s* firstObject = object->start;
struct json_value_s* app_array_value = firstObject->value;

struct json_array_s* array_value = (struct json_array_s*)app_array_value->payload;

struct json_array_element_s* b_1st = array_value->start;
struct json_value_s* b_1st_value = b_1st->value;
struct json_string_s* current_value = b_1st_value->payload;

`

How I can iterate through this linked list to insert it to another list (vector or normal array, etc) ?

MasterCna commented 3 years ago

Problem easily with more careful thinking solved:

while(last_value->next != 0)
    {
        // do something
        struct json_array_element_s* nexts = last_value;
        struct json_value_s* b_next_value = nexts->value;
        struct json_string_s* next_value = b_next_value->payload;

        last_value = last_value->next;
        KdPrint(("Size: %s\n", next_value->string));

    }