If you want to develop the code for below json format.

{
    "Products": [
        {
            "ProductNo": "11111",
            "Descr": "Myproduct-1",
            "Price": "225.36"
        },
        {
            "ProductNo": "11112",
            "Descr": "Myproduct-2",
            "Price": "235.46"
        },
        {
            "ProductNo": "11113",
            "Descr": "Myproduct-3",
            "Price": "245.56"
        },
        {
            "ProductNo": "11114",
            "Descr": "Myproduct-4",
            "Price": "255.56"
        } 
    ],
    "DateUpdated" : "20091209",
    "UpdatUser" : "Bob" 
}

Program:
$array = array (
	'Products' => array (),
	'DateUpdated' => '20091209',
	'UpdateUser' => 'Bob',
);

while ($row = mysql_fetch_assoc($result))
	$array['Products'][] = $row;

$json = json_encode($array);
 

 

Advertisements