title: How to POST list of objects as JSON from Android client to PHP REST API?
body: <p>Scenario:</p>
  
  <p>REST API: PHP Slim Framework
  Android HTTP client library: loopj </p>
  
  <p>I am storing an ITEM as json string in sqlite. </p>
  
  <p>I want to POST this JSON on server. Each item is a record in my SQLite database. </p>
  
  <p>What I am currently doing? 
  I have JSON with list of objects. I want to POST it to my PHP based REST API.</p>
  
  <p>Here is the code</p>
  
  <pre><code>if (cursor != null &amp;&amp; cursor.getCount() &gt; 0) {
              if (cursor.moveToFirst()) {
                  do {
                      Item item = new Item();
  
                      try {
  
                          item.setOfflineId(Long.parseLong(cursor.getString(0)));
                          item.setName(cursor.getString(1));
  
  
                          item.setImageLocalPath(itemPayload.getImageLocalPath());
  
  
                          item.setToUpdate(Boolean.parseBoolean(cursor.getString(3).toString()));
                          item.setDeviceID(cursor.getString(4));
                          item.setCreatedDate(cursor.getString(5));
                          //item.setImageBlob(cursor.getBlob(5));
  
                          String imageURL = itemPayload.getImageLocalPath();
                          File imageFile = new File(imageURL);
  
  
                      } catch (Exception e) {
                          Log.d("Ex", e.getMessage().toString());
                      }
  
  
                      itemList.add(item);
                  } while (cursor.moveToNext());
              }
          }
      }catch(SQLException ex){
          Log.d("DB", ex.getMessage().toString());
      }
  </code></pre>
  
  <p>The challenge?</p>
  
  <p>When I put the params for post, I also set one Param to File as I want to upload an image file as well. I know how to send one object as JSON. I want to POST the list of items (items having image Files). How to achieve this? </p>
  
  <p>One way is that I do an API POST for each object in the list. Not sure if it is a good way to do it. </p>
  
  <p>Looking for advice.</p>