dongya1228 2014-05-02 11:26
浏览 136
已采纳

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

This is my json encoded data

echo json_encode($something) 

gave me this from mongodb database

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

i need to get 535f6dc8b8082fd3f80dea0f , mukund and Lost in the woods only from that array to variables $id, $name, $Text

please help

  • 写回答

1条回答 默认 最新

  • dpqy77560 2014-05-02 11:33
    关注

    try with 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料