我想讓我的JSON輸出像這樣。從PHP正確格式化Json
{"allterms":[{"group":{"Name":"Test 1"},{"group":{"Name":"Test2","Id":"298"}}]
我當前的代碼是
while($r = mysql_fetch_assoc($rs)) {
$rows['allterms']['group'][] = $r;
}
這給了我這個
{"allterms":{"group":[{"Name":"Test1", "Id":"1740"},{"Name":"Test2","Id":"631"}}]
我如何調整我的代碼,以便每個項目都有一個父項group
。
嘗試'$行[「allterms」] [] [「羣」]',應該給你的對象數組 – kero
非常感謝Kingkero,因爲它沒有回答我形成無法接受作爲正確的,所以我接受AD7six的下面。但是,謝謝! –