Q:

How to post multiple rows (or a LIST object) to PHP using JSON (Android)

I am creating an android application in which I am using SQLite. I have one table in which I have 5 fields. There are many rows in that table and I want to send all those rows using JSON to my PHP code so I can receive the object and insert it in the MySQL database.
What is the best way to do it. I am using LIST object but don't know how I can use POST it using JSON.
Please guide!
i am using this code
mCursor =db.rawQuery("SELECT * FROM customer", null);

           while (mCursor.moveToNext()) {
                // In one loop, cursor read one undergraduate all details
                // Assume, we also need to see all the details of each and every undergraduate
                // What we have to do is in each loop, read all the values, pass them to the POJO class
                //and create a ArrayList of undergraduates
               customer = new Customer();   
               customer.CustomerName = mCursor.getString(0).toString();
               customer.Phone = mCursor.getString(1).toString();
               customer.BrandName = mCursor.getString(2).toString();
               customer.City = mCursor.getString(3).toString();
               customer.FamilyMembers = mCursor.getString(4).toString();

               customerList.add(customer);                 

            }
for (int i = 0; i < customerList.size(); i++) 
                {
                    JSONObject row = new JSONObject();
                    row.put("Customer", customerList.get(i));                        
                    json.put(row);
                }

Don't know how to post it to PHP code.

A:

You have to iterate through your List and fill an JSONArray with JSONObjects for each row. In the JSONObject you can have the key as your column-name and the value with the type you need. 
JSONArray json = new JSONArray();
for (int i = 0; i < list.size(); i++) {
    JSONObject row = new JSONObject();
    row.put("key1", list.get(i).value1);
    ...
    json.put(row);
}

(not tested). Then you can post the json.toString() to the server and retrieve it in PHP with 
$jsonstring = file_get_contents('php://input', true);

