In my PHP file I have code including:
while ($row = $result->fetch_assoc()) {
//make an array called $results
$results = array();
$results[] = array(
'contact_phonenumber' => $row['username'],
);
$json2 = json_encode($results);
//this is the response which we want in the Android app
echo $json2;
And in my Android App I have:
public void onResponse(String response) {
//print the JSON Array from the php file
System.out.println("the jsonarray is : " + response;
The response
I get when I print is in the format :
[{"contact_phonenumber":"+11111"}][{"contact_phonenumber":"+22222"}][{"contact_phonenumber":"+33333"}][{"contact_phonenumber":"+44444"}][{"contact_phonenumber":"+55555"}]
But shouldn't it be in the format ? :
[{"contact_phonenumber":"+11111"}, {"contact_phonenumber":"+22222"},{"contact_phonenumber":"+33333"}, {"contact_phonenumber":"+44444"},{"contact_phonenumber":"+55555"}]
How can I acheive this?