title: Using cJSON to read in a JSON array
body: <p>I am attempting to use the cJSON library, written by Dave Gamble, to read in the following JSON array:</p>
  
  <pre><code>"items": 
  [
      {
          "name": "command",
          "index": "X",
          "optional": "0"
      },
      {
          "name": "status",
          "index": "X",
          "optional": "0"
      }
  ]
  </code></pre>
  
  <p>From reading his <a href="https://github.com/kbranigan/cJSON/blob/master/README.md" rel="noreferrer">documentation</a>, I found ways to read in individual Objects, but nothing regarding Arrays, and I wasn't able to surmise how to do it from the examples given.  </p>
  
  <p>Here's what I'm trying:</p>
  
  <pre><code>cJSON* request_json = NULL;
  cJSON* items = cJSON_CreateArray();
  cJSON* name = NULL;
  cJSON* index = NULL;
  cJSON* optional = NULL;
  
  request_json = cJSON_Parse(request_body);
  
  items = cJSON_GetObjectItem(request_json, "items");
  
  name = cJSON_GetObjectItem(items, "name");
  index = cJSON_GetObjectItem(items, "index");
  optional = cJSON_GetObjectItem(items, "optional");
  </code></pre>
  
  <p>I know this is wrong, and not just because it's not working, but I can't figure out how to make it right.</p>
  
  <p>Obviously I'm going to need to loop the process of reading in all of the entries for each index of the array.  I have no idea how I'm going to do that though, because I don't know where I should be using the indexes in this code, or if it is even the right start.  There is a <code>cJSON_GetArrayItem()</code>, but it takes only a number (presumably an index) and no string to indicate which field it wants.</p>