Need help regarding how to use cJSON library in windows

93 views Asked by At

I am facing undefined reference issue in vs code when I run program with cJSON.h file.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"

int main() {
    const char *json_string = "JSON STRING":
    cJSON *json = cJSON_Parse(json_string);
    
    if (json != NULL) {
        cJSON *rootObject = json; // The root object of the parsed JSON

        cJSON *currentItem = rootObject->child; // Start traversing from the first element

        while (currentItem != NULL) {
            if (currentItem->type == cJSON_Object) {
                printf("Key: %s is an object.\n", currentItem->string);
                // Perform operations specific to an object here
            }

            currentItem = currentItem->next; // Move to the next element
        }

        cJSON_Delete(json); // Clean up cJSON object
    } else {
        printf("Failed to parse JSON.\n");
    }

    return 0;
}

The error is enter image description here

I have tried with below way. enter image description here

But still I am facing the issue.

This is the output enter image description here

0

There are 0 answers