0
Good morning.
I am working on a system where all Curl returns will be saved in a JSON at the end of the application to be used by the Mobile guys.
The system is all in PHP, basically it looks for data in a footstats API... The returned data is used in the system, but as soon as they come back in the request, I save them in an object...
The object is inside the public function __construct() {}
Follows code from construct
:
public function __construct()
{
$this->jsonGeral = new \stdClass();
$this->jsonHeatmap = new \stdClass();
}
Every new request data is saved this way:
public function buscarJogo($idPartida)
{
$url = "partidas/".$idPartida;
$response = $this->fazerCurl($url);
$this->jsonGeral->dadosPartida = $response;
$response = json_decode($response);
return $response;
}
the $response
, is already coming as Json, so I just put it inside the object.
In the end, when all that was needed has already been done, I make the call to turn everything into Json:
public function gerarJsonGeral()
{
$jsonGeral = stripslashes(json_encode($this->jsonGeral));
$data = date('d-m-Y-h-s-i');
$arquivo = fopen("jsonGeral-".$data.".txt", 'w');
if ($arquivo == false)
{
die('Não foi possível criar o arquivo.');
}
$texto = $jsonGeral;
fwrite($arquivo, $texto);
fclose($arquivo);
return "jsonGeral-".$data.".txt";
}
It will generate the file, apparently it will be correct, but when trying to validate, will give an error:
I have tried to modify and instead of an object, leave as GLOBAL $json
and save everything in array form, but also did not work...
I don’t know what else to do and I’m kind of desperate to try to make it work... Can anyone notice a mistake or has a solution to fix it?
Thank you in advance.
It is returning an error:
Warning: stripslashes() expects parameter 1 to be string, object given in C:\xampp\htdocs\footstats\src\Controller\CurlController.php on line 427
and the file is generated only with anull
:/– Jakson Fischer
Ah, I see the problem
– Wallace Maxters
And this was exactly the problem... Fight for the speed of help my dear :D
– Jakson Fischer
Not at all, young man. I made a few edits, in case I wanted to debug some details.
– Wallace Maxters