PHP轉換JSON數據我現在有通過CakePHP的產生JSON
物體看起來像這樣:使用CakePHP
[
{"Student":{"id":"1","name":"Pov Phearom","gender":"Male","address":"BTB","phone":"0986865898","country_id":"1"},"Country":{"id":"1","name":"Cambodia"},"Course":[]},
{"Student":{"id":"2","name":"Met Mok","gender":"Male","address":"Btb","phone":"09938273","country_id":"1"},"Country":{"id":"1","name":"Cambodia"},"Course":[]},
{"Student":{"id":"3","name":"Ovb Vannak","gender":"Male","address":"Bt","phone":"09998786","country_id":"2"},"Country":{"id":"2","name":"China"},"Course":[{"id":"2","name":"Java","description":"s","StudentsCourse":{"id":"9","student_id":"3","course_id":"2"}},{"id":"3","name":"VB","description":"s","StudentsCourse":{"id":"10","student_id":"3","course_id":"3"}},{"id":"5","name":"Android Programming","description":"Mobile developement tools","StudentsCourse":{"id":"13","student_id":"3","course_id":"5"}}]},{"Student":{"id":"4","name":"Meas Sovannara","gender":"Male","address":"Battambang","phone":"098637273","country_id":"1"},"Country":{"id":"1","name":"Cambodia"},"Course":[{"id":"2","name":"Java","description":"s","StudentsCourse":{"id":"11","student_id":"4","course_id":"2"}},{"id":"3","name":"VB","description":"s","StudentsCourse":{"id":"14","student_id":"4","course_id":"3"}},{"id":"5","name":"Android Programming","description":"Mobile developement tools","StudentsCourse":{"id":"12","student_id":"4","course_id":"5"}}]},
{"Student":{"id":"5","name":"Dara Kon","gender":"Male","address":"Battambang","phone":"098285326","country_id":"1"},"Country":{"id":"1","name":"Cambodia"},"Course":[{"id":"2","name":"Java","description":"s","StudentsCourse":{"id":"16","student_id":"5","course_id":"2"}},{"id":"3","name":"VB","description":"s","StudentsCourse":{"id":"17","student_id":"5","course_id":"3"}},{"id":"5","name":"Android Programming","description":"Mobile developement tools","StudentsCourse":{"id":"15","student_id":"5","course_id":"5"}}]}
]
我想結合各Student
因此產生的JSON對象是這樣的:
{"Student":[
{"id":"1","name":"Pov Phearom","gender":"Male","address":"BTB"},
{"id":"2","name":"Met Mok","gender":"Male","address":"Btb"},
{"id":"3","name":"Ovb Vannak","gender":"Male","address":"Bt"},
{"id":"4","name":"Meas Sovannara","gender":"Male","address":"Battambang"},
{"id":"5","name":"Dara Kon","gender":"Male","address":"Battambang"}
],"success":1,"message":"successfull"}
我想得到一些建議,我如何改進我的CakePHP數據結構以獲得所需的結果。
你做了什麼來實現這一目標? – JakeGould 2014-10-10 01:23:06