Function cJSON_GetArraySize

Synopsis

#include <cJSON.h>

int cJSON_GetArraySize(const cJSON *array)

Description

Returns the number of items in an array (or object).

Get Array size/item / object item.

Mentioned in

Source

Lines 1824-1845 in cJSON.c. Line 168 in cJSON.h.

CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array)
{
    cJSON *child = NULL;
    size_t size = 0;

    if (array == NULL)
    {
        return 0;
    }

    child = array->child;

    while(child != NULL)
    {
        size++;
        child = child->next;
    }

    /* FIXME: Can overflow here. Cannot be fixed without breaking the API */

    return (int)size;
}





Add Discussion as Guest

Log in