MongoDB PHP: How do I get ObjectId with a JSON feed? (it's blank)

ぐ巨炮叔叔 提交于 2019-12-05 10:47:01

Not sure, but maybe

echo json_encode($return, JSON_FORCE_OBJECT);

is what you need to do.

It also could be, that you need to convert $item['file'] to utf8

utf8_encode($item['file']);

before assigning it to the $return array.

MongoIds keep their values tucked away in an invisible field. It has no visible fields, so there's nothing to convert to JSON, hence {}. If you'd like to have json_encode do the "right" thing, vote for http://jira.mongodb.org/browse/PHP-154.

Echoing a MongoId converts it to a string, that's why it behaves differently.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!