首页 > 解决方案 > 回显/打印特定 JSON 字段 PHP

问题描述

我有一个具有以下结构的 JSON:

{
    "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
}

我想捕获“totalPages”字段

我的部分代码(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'];
    }

然而,答案是:

注意:第 39 行 C:\xampp\htdocs\acre.php 中的数组到字符串转换

标签: phpjson

解决方案


推荐阅读