So here the thing:
I am developing a backend (php) that connects with Microsoft SQL Server with android application to be the user interface.
However, I am facing a problem when it comes to encoding json with php.
It is more than fair to say that I am a beginner in php.
This is my code:
$result = sqlsrv_query( $conn, 'select * from table1');
$row = sqlsrv_fetch_array($result);
$array = array();
while($row =sqlsrv_fetch_array($result))
{
$array[]=$row;
}
echo json_encode(array("data"=>array_values($array)));
So the table actually has nothing so far: just two attributes: name and age
The problem here is that the return is being as follows:
{"data":[{"0":"Miriana","name":"Miriana","1":null,"age":null},{"0":"Luke","name":"Luke","1":null,"age":null},{"0":"Sara","name":"Sara","1":null,"age":null},{"0":"Fuss","name":"Fuss","1":20,"age":20}]}
There is always a number preceding the values with a value then the real key and a value.
For example:
"0":"Miriana"
"1":null
Thanks so much for anyone who would check this out.
**I checked those links: Decode json With PHP not working Parsing JSON with PHP Encoding JSON with PHP issues with array **