2017-03-19 103 views
-1

我嘗試使用此方法檢索單詞「John」。無法檢索此JSON數據

代碼

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

JSON

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

我認爲首先squarre支架在這裏阻止我 感謝您的幫助

回答

2

應該以這種方式工作的事:

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

試試這個:

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

enter image description here

enter image description here