我有以下代码:
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->bbcData->programmeData;
$result = $collection->find( [ '_id' => 'b007jwd9'] );
foreach ($result as $entry) {
echo $entry['_id'], ': ', $entry['complete_title'], "\n";
}
?>JSON如下所示:
{"complete_title":{"name":"wimsey - murder must advertise","episode":"sudden decease of a man in dress clothes"},"media_type":"audio","_id":"b007jwd9","categories":{"category1":["drama", "crime"]}}我想打印出complete_title的名称,但是文档没有显示这方面的语法。目前,我收到一个错误,说complete_title是一个BSONDocument,所以它不能转换为字符串。
发布于 2017-04-01 19:41:26
使用iterator_to_array获取数组。
foreach ($result as $entry) {
$array = iterator_to_array($entry['complete_title']);
echo $entry['_id'], ': ', $array['name'], "\n";
}https://stackoverflow.com/questions/43158399
复制相似问题