Receive and treat JSON with PHP

Asked

Viewed 526 times

0

Good evening guys, I’m new to the world of programming, 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 treat the response and display on the screen.

  • It’s okay that you’re using JSON as an object, but in what language are you programming to try to manipulate the object? By print_r I guess PHP, right? If positive make edits to make it clearer.

1 answer

1

  • Since your answer is an array, you must iterate on a foreach: https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php

  • It is an array composed of two objects, and each object has a 10 attributes, yet I can sweat the foreach?

  • I am deducing that yes based on my knowledge with Angular. In the case as your answer is data[0]; data[1]... and the attributes are within data[i], that is, there will be no problems, so I understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.