2016-07-10 3 views
-1

저는 몇 시간 동안 인터넷을 검색해 왔지만 그걸 알아낼 수 없습니다.json array에서 php json_decode가 작동하지 않습니다.

<?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 
관련 문제