如何选择数据并从包含子数组的json数组中显示它?

时间:2014-05-02 11:26:18

标签: php json mongodb

这是我的json编码数据

echo json_encode($something) 

从mongodb数据库给我这个

[
    {
        "_id":{ "$id":"535f6dc8b8082fd3f80dea0f"},
        "val":"mukund",
        "value":"Lost in the woods"
    }
]

我只需要从该数组获取535f6dc8b8082fd3f80dea0fmukundLost in the woods变量$ id,$ name,$ Text

请帮助

1 个答案:

答案 0 :(得分:1)

尝试使用json_decode()

$j = '[{"_id":{"$id":"535f6dc8b8082fd3f80dea0f"},"val":"mukund","value":"Lost in the woods"}]';
$r = json_decode($j);
 echo (string)$r[0]->_id->{'$id'}; //535f6dc8b8082fd3f80dea0f
 echo $r[0]->val; //mukund
 echo $r[0]->value; //Lost in the woods