简体   繁体   English

php json_decode 不适用于 json 数组

[英]php json_decode not working on json array

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM