I have been searching the internet for hours now, and i can't figure it out.
我已经在网上搜索了好几个小时了,我弄不清楚。
<?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'];
?>
Im just simply trying to parse some json but the website says this:
我只是想解析json,但是网站上说:
NULL
Notice: Undefined variable: pages in C:\Users\hazzj\Desktop\Stuff\Apache-Server\htdocs\WMS\Author\submit\test.php on line 7
1 个解决方案
#1
0
You'd missed out commas between strings {}. Use this modified $json variable:
您会错过字符串{}之间的逗号。使用这个修改后的$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
#1
0
You'd missed out commas between strings {}. Use this modified $json variable:
您会错过字符串{}之间的逗号。使用这个修改后的$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