Osc*_*son 5 php database json feed mongodb
我通过GridFS存储文件并保存id,如下所示:
$file_id = $gridfs->storeUpload('texture');
$item = array(
'name'=>$_POST['name'],
'description'=>$_POST['description'],
'price'=>$_POST['price'],
'categories'=>$category_array,
'tags'=>$tag_array,
'file'=>$file_id
);
$collection->insert($item);
Run Code Online (Sandbox Code Playgroud)
并通过终端和find()"文件"返回:ObjectId("4cbe9afe460890b774110000")
如果我这样做是为了创建一个JSON提要,所以我可以获取信息,我的应用程序"文件"是空白的...为什么这样?:
foreach($cursor as $item){
$return[$i] = array(
'name'=>$item['name'],
'description'=>$item['description'],
'file'=>$item['file']
);
$i++;
}
echo json_encode($return);
Run Code Online (Sandbox Code Playgroud)
对我来说,奇怪的是我为什么要这样做:
foreach($cursor as $item){
echo $item['file'];
}
Run Code Online (Sandbox Code Playgroud)
并把它拿回来?
哦,这是Feed返回的内容:
[{"name":"Tea Stained Paper 1","description":"Grungy paper texture stained with tea and coffee.","file":{}},{"name":"Worn Metal 1","description":"A grooved, worn old metal texture","file":{}}]
Run Code Online (Sandbox Code Playgroud)
不确定,但也许
echo json_encode($return, JSON_FORCE_OBJECT);
Run Code Online (Sandbox Code Playgroud)
是你需要做的.
它也可能是,您需要转换$item['file']为utf8
utf8_encode($item['file']);
Run Code Online (Sandbox Code Playgroud)
在将其分配给$return数组之前.
| 归档时间: |
|
| 查看次数: |
2058 次 |
| 最近记录: |