I was in the middle of spending all day trying to fix it and it all failed, I wanted json_decode from my phalcon website. My source code in Controller:
class JsonController extends Controller
{
public function indexAction()
{
@header('Content-Type: application/json');
$response["status"] = "true";
$response["code"] = 'AAAAA'; //["product"]
$response["name"] = 'BBBB'; //["product"]
echo json_encode($response,JSON_UNESCAPED_UNICODE);
exit;
}
}
When I retrieved data from the phacon website (https://example.com/json/) , it all failed. Source get data json:
<?php
$json = file_get_contents('https://example.com/json/');
$read_json = json_decode($json,true);
echo $read_json['status'].'<br>';
echo $read_json['name'].'<br>';
echo $read_json['name'].'<br>';
?>
however, when I created a static php page outside of the controller (in public/json.php => https://example.com/json.php) , it worked
json.php file:
<?php
@header('Content-Type: application/json');
$response["status"] = "true";
$response["code"] = 'AAAAA'; //["product"]
$response["name"] = 'BBBB'; //["product"]
echo json_encode($response,JSON_UNESCAPED_UNICODE);
exit;
?>
Get data json in public:
<?php
$json = file_get_contents('https://example.com/json.php');
$read_json = json_decode($json,true);
echo $read_json['status'].'<br>';
echo $read_json['name'].'<br>';
echo $read_json['name'].'<br>';
?>
Look forward to the help
Thank you