2016-07-10 20 views
-1

私は数時間インターネットを検索していますが、私はそれを理解できません。php json_decodeがjson配列で動作していません

<?php 
$json = '{"pages":[{"name": "Page1","inputs":[{"title": "Catagory","name": "catagory","type": "radio","options":[{"name": "Paper","value": "paper"}{"name": "Letter","value": "letter"}]}{"title": "Title","name": "title","type": "text"}{"title": "File","name": "file","type": "file","fileName": "?pages[0].inputs[0]"}{"title": "Submit","type": "submit"}]}]}'; 

$result = json_decode($json, true); 
var_dump($result); 
echo $result['pages'][0]['name']; 
echo $pages[0]['name']; 
?> 

イム単にいくつかのJSONを解析しようとしているが、ウェブサイトには、これを言う:

NULL 
Notice: Undefined variable: pages in C:\Users\hazzj\Desktop\Stuff\Apache-Server\htdocs\WMS\Author\submit\test.php on line 7 
+2

JSONが無効です - http://jsonlint.comで確認してください –

答えて

0

あなたは、文字列{}の間にカンマを逃したと思います。この変更された$ json変数を使用してください:

$json = '{"pages":[{"name": "Page1","inputs":[{"title": "Catagory","name": "catagory","type": "radio","options":[{"name": "Paper","value": "paper"},{"name": "Letter","value": "letter"}]},{"title": "Title","name": "title","type": "text"},{"title": "File","name": "file","type": "file","fileName": "?pages[0].inputs[0]"},{"title": "Submit","type": "submit"}]}]}'; 

$result = json_decode($json, true); 
echo $result['pages'][0]['name']; // Output: Page1 
echo $pages[0]['name'];   // Not sure what this $pages variable is