0

I have a JSON with the following structure:

{
    "content": [
        {
            "id": 119273908,
            "numeroPeca": "0008919712005802000110000125",
        },
        {
            "id": 25926466,
            "numeroPeca": "0500013942009802003310000126",
        },
        {
            "id": 124435361,
            "numeroPeca": "0800040772017802001510000124",

        },
        {
            "id": 79760181,
            "numeroPeca": "0066239062010802000110000118",
        }
],
    "last": false,
    "totalElements": 6402,
    "totalPages": 4,
    "size": 2000,
    "number": 0,
    "sort": null,
    "first": true,
    "numberOfElements": 2000
}

I would like to capture the "totalPages" field

my partial code (PHP):

$response = curl_exec($curl);
$err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {

      $array = json_decode($response, true);
      echo $array['content'];
    }

However, the answer is:

Notice: Array to string conversion in C:\xampp\htdocs\acre.php on line 39 Array

  • 1
    `echo $array['totalPages'];` – cOle2 Jan 22 '20 at 22:37
  • [possible duplicate](https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) - `$array['content']` is an array, hence echoing it will give _array to string conversion_ notice. – jibsteroos Jan 22 '20 at 22:39
  • @cOle2 I tried and it didn't work –  Jan 23 '20 at 01:28

0 Answers0