Json formats
Posted: Tue Sep 08, 2015 11:00 am
Hi Team,
I need to create a JSON from my php. As of now I am able to get the JSON, but it is needed in a different format.
Mentioned below is the code I am using
<?php
$connectString = 'host=localhost dbname=postgis_21_sample user=postgres password=postgresql';
$link = pg_connect($connectString);
if (!$link) {
echo "error";
} else {
$result = pg_query($link, $sql);
//$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode($rows,true);
}
?>
Attached is the image json.png which show how the following code shows the output.
Attached is the image of the required format.
Please help me to get the desired format.
Thanks
Aditya Kumar
I need to create a JSON from my php. As of now I am able to get the JSON, but it is needed in a different format.
Mentioned below is the code I am using
<?php
$connectString = 'host=localhost dbname=postgis_21_sample user=postgres password=postgresql';
$link = pg_connect($connectString);
if (!$link) {
echo "error";
} else {
$result = pg_query($link, $sql);
//$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode($rows,true);
}
?>
Attached is the image json.png which show how the following code shows the output.
Attached is the image of the required format.
Please help me to get the desired format.
Thanks
Aditya Kumar