Function cJSON_InsertItemInArray

Synopsis

#include <cJSON.h>

cJSON_bool cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)

Description

Update array items.

Replace array/object items with new ones.

Mentioned in

Source

Lines 2259-2286 in cJSON.c. Line 242 in cJSON.h.

CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
{
    cJSON *after_inserted = NULL;

    if (which < 0)
    {
        return false;
    }

    after_inserted = get_array_item(array, (size_t)which);
    if (after_inserted == NULL)
    {
        return add_item_to_array(array, newitem);
    }

    newitem->next = after_inserted;
    newitem->prev = after_inserted->prev;
    after_inserted->prev = newitem;
    if (after_inserted == array->child)
    {
        array->child = newitem;
    }
    else
    {
        newitem->prev->next = newitem;
    }
    return true;
}





Add Discussion as Guest

Log in