ผมมีลิงค์ข้อมูล json แล้วผมก็ใช้ file_get_contents("link") มา แต่พอนำไป decode
มันฟ้องว่า Input is not an array
(ข้อมูล json ในลิงค์ >>>
[{"AC_AC_FUB":{"line":"AC_AC_FUB","PROCESS":"AC. MODEL CHANGE L\/M","START":"10:42:17","LOSS":"10"}}]
)
Code (PHP)
<?php
// Define recursive function to extract nested values
function printValues($arr) {
global $count;
global $values;
// Check input is an array
if(!is_array($arr)){
die("ERROR: Input is not an array");
}
/*
Loop through array, if value is itself an array recursively call the
function else add the value found to the output items array,
and increment counter by 1 for each value found
*/
foreach($arr as $key=>$value){
if(is_array($value)){
printValues($value);
} else{
$values[] = $value;
$count++;
}
}
// Return total count and values found in array
return array('total' => $count, 'values' => $values);
}
$jsont = file_get_contents("http://43.72.52.84/monitor/mc_status/downtime_layout.php?business=AC");
// Decode JSON data into PHP associative array format
$arr = json_decode($jsont,true);
// Call the function and print all the values
$result = printValues($arr);
echo "<h3>" . $result["total"] . " value(s) found: </h3>";
echo implode("<br>", $result["values"]);
echo "<hr>";
// Print a single value
echo $arr["AC_AC_FUM"]["line"] . "<br>";
echo $arr["AC_AC_FUM"]["PROCESS"] . "<br>";
echo $arr["AC_AC_FUM"]["START"] . "<br>";
?>
Warning: file_get_contents(http://43.72.52.84/monitor/mc_status/downtime_layout.php?business=AC): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.