Problem with json slim framework

0

I am doing an api to do the integration of two different systems, the system sends me the following json:

cJson = [{"TESTE": "1"}]

I was 3 days with a problem because I was not able to get the json that the other system sent me via post with neither of the two methods below:

$dados = $request->getBody();

$dados = $request->getParsedBody();

I solved this problem and now I can get the json that the other system sends me with the following method:

$dados = (string) $resquest->getBody();

But this method just above returns a string, and I need to turn it into array or object to insert it into the database. when I echo what is returned to me is just what I want to see just below:

echo $dados; 
resultado:   [{"TESTE": "1"}]

But when I use a json_decode it does not return anything returns null, example:

echo json_decode($dados);
resultado: null

Would it be a string? Is there any way I could work it out? I already have the data but I can not manipulate it to insert into the database ...

    
asked by anonymous 21.06.2017 / 17:16

1 answer

1

There is nothing wrong with converting the string to JSON. The problem is that you can not display the result with echo () , because the return of the json_decode () function is an array.

Try using print_r () :

print_r(json_decode('[{"TESTE": "1"}]'));
resultado: Array ( [0] => stdClass Object ( [TESTE] => 1 ) )
    
21.06.2017 / 17:31