无法检索此JSON数据

时间:2017-03-19 03:42:54

标签: php arrays json

我试过检索" John"例如,使用这种方式。

代码

$decoded = json_decode('$thejson');  
$myvar =  $decoded->name;
echo $myvar;

JSON

[
  {
    "name": "John",
    "age": "50",
    "Job": "Developer"
  }
]

我认为第一个squarre括号是阻止我的事情 谢谢你的帮助

2 个答案:

答案 0 :(得分:2)

它应该以这种方式工作:

$myvar =  $decoded[0]->name;

答案 1 :(得分:0)

试试这个:

$decoded = json_decode($thejson,TRUE);  
$myvar =  $decoded[0]['name'];

enter image description here

enter image description here

相关问题