我正在使用两个php文件,第一个是创建JSON,第二个应该能够读取它(但不起作用)
/*
Template Name: JANDERS
*/
header('Content-Type: application/json; charset=utf-8');
$myArr = array("John", "Mary", "Peter", "Sally");
$myJSON = json_encode($myArr);
echo $myJSON;
?>
// Prints on screen: ["John","Mary","Peter","Sally"]
我想在这里查看和使用JSON:
<?php
$urlss = "https://example.com/22.php";
//call api
$jsonss = file_get_contents($urlss);
$jsontwoss = json_decode($jsonss);
var_dump(json_last_error(), json_last_error_msg());
//echo $json;
echo $jsontwoss;
?>
//returns int(4) string(12) "Syntax error"
这是怎么了? 谢谢!
答案 0 :(得分:0)
您正在尝试将数组作为字符串回显。
$jsontwoss = json_decode($jsonss);
产生一个数组。
如果要查看结果,请使用
print_r($jsontwoss);
第12行