【发布时间】:2012-07-29 05:25:35
【问题描述】:
我正在开发 php 应用程序,我在其中查询数据库并将生成的结果发送回 html 客户端。
目前我正在使用 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"
}
}
}
}
编码后显示 null 而不是 JSON。 我需要序列化它吗? 任何建议都将是可观的。 谢谢。
【问题讨论】:
标签: php arrays serialization json