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

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图