我正在開發PHP應用程序,其中我正在查詢數據庫並將生成的結果發送回html客戶端。PHP json_encode不與對象數組一起工作
目前我正在使用php函數json_encode獲取JSON編碼的對象數組。
但編碼後,我得到了我的結果中的空數組。
以下結構是編碼前JSON
array(2) {
[0]=>
object(ProductComment)#6 (2) {
["_productId":"ProductComment":private]=>
string(1) "1"
["_commentArray":"ProductComment":private]=>
array(2) {
[0]=>
array(3) {
["comment"]=>
string(9) "comment 1"
["creationDate"]=>
string(19) "2000-02-02 00:00:00"
["userName"]=>
string(8) "Ashutosh"
}
[1]=>
array(3) {
["comment"]=>
string(13) "comment1 text"
["creationDate"]=>
string(19) "2012-07-31 10:20:27"
["userName"]=>
string(8) "Ashutosh"
}
}
}
[1]=>
object(ProductComment)#5 (2) {
["_productId":"ProductComment":private]=>
string(1) "2"
["_commentArray":"ProductComment":private]=>
array(2) {
[0]=>
array(3) {
["comment"]=>
string(22) "comment2 product2 text"
["creationDate"]=>
string(19) "2012-07-31 10:48:06"
["userName"]=>
string(8) "Ashutosh"
}
[1]=>
array(3) {
["comment"]=>
string(22) "comment2 product4 text"
["creationDate"]=>
string(19) "2012-07-31 10:48:14"
["userName"]=>
string(8) "Ashutosh"
}
}
}
}
和編碼它示出,而不是JSON空之後。 我需要序列化它嗎?任何建議都將是可觀的。 感謝你。
類似的東西:http://stackoverflow.com/questions/6836592/serializing-php-object-to-json – MarcDefiant 2012-07-31 12:43:29