How to encode JSON in below format:
{
"jobs": [
{
"JobID":"1",
"JobTitle":"CEO"
}
]
}
This is what I achieved:
[
{
"JobID":"1",
"JobTitle":"CEO"
}
]
Here is my PHP script using to mysql data to JSON:
<?php
......
$strSQL = "SELECT * FROM jobs WHERE 1 ";
$objQuery = mysql_query($strSQL);
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
I am not a native PHP developer, that's why not so strong in web development and i tried some tutorials and blogs but did not get any solution !