Cross dressers:json_decode数组返回缺少数组索引

我正在尝试为 jaredhendrickson13 / pfsense-api(https://github.com/jaredhendrickson13/pfsense-api)构建一个 web-gui,要么我无法获得返回的数组索引,要么它们不在那里。

我使用 laravel8 与 PHP 7.4

我的代码得到响应;

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://192.168.1.175/api/v1/firewall/rule",
    CURLOPT_TIMEOUT => 30000,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_SSL_VERIFYPEER => false, //add line
    CURLOPT_SSL_VERIFYHOST => false, //add line
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
    CURLOPT_USERPWD => "$username:$password",
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        // Set Here Your Requesred Headers
        'Content-Type: application/json',
    ),
));
$response = curl_exec($curl);
curl_close($curl);
$object = json_decode($response,true);
return $object;

和输出我 gettins 是;

{
    "status": "ok",
    "code": 200,
    "return": 0,
    "message": "Success",
    "data": [
        {
            "id": "",
            "tracker": "1665883545",
            "type": "pass",
            "intece": "wan",
            "ipprotocol": "inet",
            "tag": "",
            "tagged": "",
            "max": "",
            "max-src-nodes": "",
            "max-src-conn": "",
            "max-src-states": "",
            "statetimeout": "",
            "statetype": "keep state",
            "os": "",
            "protocol": "tcp",
            "source": {
                "any": ""
            },
            "destination": {
                "address": "192.168.1.201"
            },
            "descr": "Test2",
            "created": {
                "time": "1665883545",
                "username": "admin@192.168.1.100 (Local Database)"
            },
            "updated": {
                "time": "1665883556",
                "username": "admin@192.168.1.100 (Local Database)"
            }
        },
        {
            "id": "",
            "tracker": "1665883538",
            "type": "pass",
            "intece": "wan",
            "ipprotocol": "inet",
            "tag": "",
            "tagged": "",
            "max": "",
            "max-src-nodes": "",
            "max-src-conn": "",
            "max-src-states": "",
            "statetimeout": "",
            "statetype": "keep state",
            "os": "",
            "protocol": "tcp",
            "source": {
                "any": ""
            },
            "destination": {
                "address": "192.168.1.202"
            },
            "descr": "Test1",
            "created": {
                "time": "1665883538",
                "username": "admin@192.168.1.100 (Local Database)"
            },
            "updated": {
                "time": "1665883566",
                "username": "admin@192.168.1.100 (Local Database)"
            }
        },
        {
            "type": "pass",
            "ipprotocol": "inet",
            "descr": "Default allow LAN to any rule",
            "intece": "lan",
            "tracker": "0100000101",
            "source": {
                "network": "lan"
            },
            "destination": {
                "any": ""
            }
        },
        {
            "type": "pass",
            "ipprotocol": "inet6",
            "descr": "Default allow LAN IPv6 to any rule",
            "intece": "lan",
            "tracker": "0100000102",
            "source": {
                "network": "lan"
            },
            "destination": {
                "any": ""
            }
        }
    ]
}

是邮递员的回应,与我的输出相同;

{
"status": "ok",
"code": 200,
"return": 0,
"message": "Success",
"data": [
    {
        "id": "",
        "tracker": "1665883545",
        "type": "pass",
        "intece": "wan",
        "ipprotocol": "inet",
        "tag": "",
        "tagged": "",
        "max": "",
        "max-src-nodes": "",
        "max-src-conn": "",
        "max-src-states": "",
        "statetimeout": "",
        "statetype": "keep state",
        "os": "",
        "protocol": "tcp",
        "source": {
            "any": ""
        },
        "destination": {
            "address": "192.168.1.201"
        },
        "descr": "Test2",
        "created": {
            "time": "1665883545",
            "username": "admin@192.168.1.100 (Local Database)"
        },
        "updated": {
            "time": "1665883556",
            "username": "admin@192.168.1.100 (Local Database)"
        }
    },
    {
        "id": "",
        "tracker": "1665883538",
        "type": "pass",
        "intece": "wan",
        "ipprotocol": "inet",
        "tag": "",
        "tagged": "",
        "max": "",
        "max-src-nodes": "",
        "max-src-conn": "",
        "max-src-states": "",
        "statetimeout": "",
        "statetype": "keep state",
        "os": "",
        "protocol": "tcp",
        "source": {
            "any": ""
        },
        "destination": {
            "address": "192.168.1.202"
        },
        "descr": "Test1",
        "created": {
            "time": "1665883538",
            "username": "admin@192.168.1.100 (Local Database)"
        },
        "updated": {
            "time": "1665883566",
            "username": "admin@192.168.1.100 (Local Database)"
        }
    },
    {
        "type": "pass",
        "ipprotocol": "inet",
        "descr": "Default allow LAN to any rule",
        "intece": "lan",
        "tracker": "0100000101",
        "source": {
            "network": "lan"
        },
        "destination": {
            "any": ""
        }
    },
    {
        "type": "pass",
        "ipprotocol": "inet6",
        "descr": "Default allow LAN IPv6 to any rule",
        "intece": "lan",
        "tracker": "0100000102",
        "source": {
            "network": "lan"
        },
        "destination": {
            "any": ""
        }
    }
]

}

如何提取“数据”部分放入 foreach 循环?

它看起来像响应有点坏了,但我不能决定我是否做错了。

谢谢

0

从原始 curl 更改为 Http 类工作。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(897)
Es6数组方法:ES6/Typescript:堆叠映射和筛选高级数组方法
上一篇
龙之崛起免cd补丁:在CSS中崛起(PPT)动画
下一篇

相关推荐

  • javascript判断题:JavaScript中的函数是如何定义的?

    示例示例判断题是指使用语言来实现一些逻辑判断的题目,主要是使用if语句来实现。例如:…

    2023-06-28 15:27:44
    0 97 95
  • css动画执行一次:Unlock Your Potential with CSS Animations

    CSS动画可以使元素在指定的时间内从一种样式变化到另一种样式。要实现CSS动画只执行一次,需要使用animation-iteration-count属性,该属性可以设置动画的重复次数。…

    2023-05-02 02:07:41
    0 37 54
  • javascript折叠菜单:使用方法

    javascript折叠菜单是指使用javascript实现的折叠菜单,它可以实现菜单的展开和折叠功能,以更好的帮助用户浏览网页。…

    2023-08-06 16:28:04
    0 96 60
  • javascript是java语言吗:JavaScript与Java之间的区别

    示例示例No,不是java语言。和Java是两种完全不同的编程语言,它们之间没有直接的联系。是一种轻量级的、跨平台的、弱类型的、基于原型的、多范式的编程语言,它的设计目的是为了使网页上的动态内容更容易创建和维护。…

    2023-05-17 04:31:38
    0 81 99
  • jquery 改变css: blue});

    示例示例jQuery 可以使用 css() 方法来改变 CSS 属性,其语法如下:$().css(, value);…

    2023-04-30 02:29:44
    0 40 70
  • css起源下载:Unlock the Power of CSS to Create Amazing Web Designs

    CSS(Cascading Style Sheets)是一种用来定义HTML文档的样式表语言。它可以让你使用样式属性来定义文档的外观,如字体、颜色、背景图像等。…

    2023-03-04 03:20:22
    0 10 35
  • javascript定义The Language of the Web

    示例示例是一种轻量级的脚本语言,它可以在浏览器中运行,用于添加动态效果到网页,以及创建更复杂的Web应用程序。下面是一个简单的代码示例,用于显示一个弹出框:…

    2023-04-07 12:46:01
    0 86 78
  • javascript警告框请注意您的输入!

    javascript警告框是一种浏览器弹出框,用于向用户显示一条警告信息。它可以帮助用户在网页中做出正确的选择,以避免出现不必要的错误。…

    2023-10-02 07:40:28
    0 62 64

发表评论

登录 后才能评论

评论列表(83条)