Receiving and handling JSON with PHP

0

Good evening, I'm new to the programming world, I'm getting information from a webservice via json, and now I need to manipulate this json's information, for example, I'd like to just get the [name], someone could give me one north. Thanks in advance.

//Recebendo o Json
$dados= json_decode($response);
echo "<pre>";
print_r($dados);
echo "</pre>";

// Dados Exibidos
stdClass Object
(
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [uuid] => 8ec4e4c4d6c78a7ab7692c410448a5b7ebcb3bad
                    [nome] => TESTANDOAPI2
                    [slug] => testandoapi2
                    [created] => 2018-10-15 13:06:16
                    [total] => 0
                )

            [1] => stdClass Object
                (
                    [uuid] => aa02900bff1081c1a12d998e9a15d6c01845af84
                    [nome] => TESTANDOAPI
                    [slug] => testandoapi
                    [created] => 2018-10-15 12:53:05
                    [total] => 0
                )

        )

    [total] => 2
)
  

I'm using PHP to receive the data, I need to handle the response and display it on the screen.

    
asked by anonymous 16.10.2018 / 03:09

2 answers

1

By deducting by print_r what PHP you are using to get the JSON object ...

This question was answered in the Stack in English: link

Just translating:

$obj = json_decode($result); // resultado da sua requisição
echo $obj->nome; // atributo do objeto que deseja obter
    
16.10.2018 / 03:17
-2

Just use the array principle, once you access an array, just identify the index that can be by name or position understands? in this case you can access in two ways:

$obj->nome;
$obj[1];

But be very careful what comes from outside, make a filter at least as security. follows documentation: link

    
16.10.2018 / 16:19