duanlu6114
2019-06-11 06:13
浏览 57
已采纳

如何在mysql json数组中编写SELECT查询

I am trying to get the email from the array json, but it returns null value

[
    {
        "name": "Arun", 
        "email": "arun@arun.com"
    }, 
    {
        "name": "Arun kumar",
        "email": "arunkumar@gmail.com"
    }
]

and my Json query is select json->>"$.name" as email from json

But this query is return null value

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongmeiran609914 2019-06-11 06:53
    最佳回答

    I tested the following and worked for me on your json sample

    $json='[{"name": "Arun", "email": "arun@arun.com"}, {"name": "Arun kumar", "email": "arunkumar@gmail.com"}]';
    $data=json_decode($json,true);
    
    foreach ($data as $key => $value) {
        echo $value["email"] . "<br>";
    }
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)