2016-10-09 14 views
0

私はjson文字列を持っています。しかし、私は値にアクセスすることはできません。PHP jsonデコード配列

$json_string : '{"05526":[{"name":"rapertuar","surname":"xyz","notes":[{"mat1":"59","eng2":"60"},{"mat2":"59","eng2":"60"}]}]}'; 
$content = file_get_contents($json_string); 
$json_a = json_decode($content, true); 

echo $json_a['05526']['0']['name']; 
echo $json_a['05526']['0']['name']['notes']['0']['mat1']; 

このコードを修正するにはどうすればよいですか?あなたは、文字列でJSONを格納し、それをデコードしている場合file_get_contentsを使用する必要はありませんあなた

+1

'file_get_contents($ json_string)'?それは何ですか? –

+0

文字列だけの場合は、なぜファイルにアクセスしようとしますか? – Rizier123

答えて

1
$json_string : '{"05526":[{"name":"rapertuar","surname":"xyz","notes":[{"mat1":"59","eng2":"60"},{"mat2":"59","eng2":"60"}]}]}'; 

// you don't need this line 
//$content = file_get_contents($json_string); 
$json_a = json_decode($json_string, true); 

echo $json_a['05526']['0']['name']; 
echo $json_a['05526']['0']['name']['notes']['0']['mat1']; 
1

をありがとうございます。以下の方法に従ってください:

$json_string = '{"05526":[{"name":"rapertuar","surname":"xyz","notes":[{"mat1":"59","eng2":"60"},{"mat2":"59","eng2":"60"}]}]}'; 
$json_a = json_decode($json_string, true); 

echo $json_a['05526']['0']['name']; // rapertuar 
echo $json_a['05526']['0']['notes']['0']['mat1']; // 59 
+0

私の問題を解決してくれてありがとう。 – sputn1k