I have looked around for over a few hours and most of the post I see are from way back when, so maybe I just don't understand or it might be outdated. I have two problems.
I have an Json object and Json Array that comes out like this:
{"command":"update", "Data":["first data","second data","third data","fourth data"]}
I want it it to read like this:
{"command":"update", "Data":[{"1":"first data"},{"2":"second data"},{"1":"third data"},{"2":"fourth data"}]}
I am unclear how to add the 1 & 2 so I can know what to pull on the php side.And it might not be the proper format either, but you will get an ideal. Android code:
JSONObject parent = new JSONObject();
JSONArray child = new JSONArray();
child.put("first data");
child.put("second data");
parent.put("Data", child);
Next problem on my php side is pulling the data so I can put it into my database and I am unsure exactly how this is done:
// DECODE OUR JSON FROM ANDROID
$data = json_decode(file_get_contents('php://input'), true);
// FOR LOOP TO INSERT DATA INTO DATABASE
for($i=0; $i<count($obj['Data']); $i+=2)
{
// need to get 1 & 2 values to insert into database
//$first = NEED VALUE OF 1
//$second = NEED VALUE OF 2
// mysqli statement to insert into database
$Q = "INSERT INTO `DATA_TABLE` (data1, data2) VALUES ('$first', '$second');
mysqli_query($conn, $Q);
}