$proj_document = [{"name":"project__1MfEqp.jpg", "type":"image\/jpeg", "size":4792, "path":"uploads\/project__1MfEqp.jpg"}];
我想单独使用名称,project__1MfEqp.jpg
我用过
$proj_document[0]['name'] and
$proj_document[0]->name;
但是没有为我工作。如何从上面的json格式单独获取名称?谁能帮我??感谢。
答案 0 :(得分:3)
您需要执行以下操作: -
<?php
$proj_document = '[{"name":"project__1MfEqp.jpg", "type":"image\/jpeg", "size":4792, "path":"uploads\/project__1MfEqp.jpg"}]';
$proj_document_array = json_decode($proj_document); // convert json data into array
echo "<pre/>";print_r($proj_document_array); // print that array to check it's format
echo $proj_document_array[0]->name; // get the name attribute
?>
输出: - https://eval.in/407953