我无法获得用于创建动态列网格的有效JSON格式。 这是我有的: PHP
$query="select * from mytable";
$rs = mysql_query($query);
$rows = array();
while($r = mysql_fetch_object($rs)) {
$rows[] = $r;
}
echo json_encode($rows);
//Results:
[{"EmpID":"12345","Name":"James","Account":"New Account1","Group1":"Library","Food_Bill_Date":null,"Food_Bill_Amount":null,"Food_Bill_Number":null},
{"EmpID":"12346","Name":"David","Account":"New Account2","Group2":"Lab","Food_Bill_Date":null,"Food_Bill_Amount":null,"Food_Bill_Number":null},
{"EmpID":"12347","Name":"Ramsy","Account":"New Account2","Group2":"Lab","Food_Bill_Date":null,"Food_Bill_Amount":null,"Food_Bill_Number":null},
............
.............
............
]
需要从结果数组中分隔行和列。
中需要
[
{
"columns": [
{
"text": "SampleK",
"datafield": "sample1",
"width": "30"
},
{
"text": "ID",
"datafield": "id",
"width": "30"
}
]
}
{
"rows": [
{
"id": "1",
"name": "Hot Chocolate",
"type": "Chocolate Beverage",
"calories": "370",
"totalfat": "16g",
"protein": "14g"
},
{
"id": 2,
"name": "Peppermint Hot Chocolate",
"type": "Chocolate Beverage",
"calories": "440",
"totalfat": "16g",
"protein": "13g"
},
]
}
]
请帮忙。