I am attempting to use the cJSON library, written by Dave Gamble, to read in the following JSON array:
\"items\":
[
{
\"name\": \"command\",
If you want to run slightly faster, this is what the code looks like:
void parse_array(cJSON *array)
{
cJSON *item = array ? array->child : 0;
while (item)
{
cJSON *name = cJSON_GetObjectItem(item, "name");
cJSON *index = cJSON_GetObjectItem(item, "index");
cJSON *optional = cJSON_GetObjectItem(item, "optional");
item=item->next;
}
}
This avoids the O(n^2) cost that RBerteig correctly points out.
Call with:
parse_array(cJSON_GetObjectItem(cJSON_Parse(request_body),"items"));