gpt4 book ai didi

PHP JSON 解析,缺少项目

转载 作者:可可西里 更新时间:2023-11-01 01:04:32 25 4
gpt4 key购买 nike

<分区>

当我在浏览器中输入一个 URL 时,我得到了输出(如下)

{"categories":[{"id":"16","name":"Arm Locks"},{"id":"555","name":"Articles"},{"id":"19","name":"Back Control"},{"id":"21","name":"Brazilian Jiu Jitsu"},{"id":"12","name":"Chokes"},{"id":"15","name":"Crank"},{"id":"14","name":"Escapes"},{"id":"554","name":"Grappling Videos"},{"id":"10","name":"Guard and Rubber Guard"},{"id":"13","name":"Guard Breaks"},{"id":"23","name":"Half Guard"},{"id":"26","name":"Japanese Jujutsu"},{"id":"1","name":"Jiu Jitsu Training"},{"id":"5","name":"Jiu Jitsu Videos"},{"id":"25","name":"Leg Locks"},{"id":"27","name":"MMA"},{"id":"17","name":"Mount"},{"id":"30","name":"North South Position"},{"id":"556","name":"Platinum Members Only"},{"id":"29","name":"Self Defense"},{"id":"18","name":"Side Control"},{"id":"28","name":"Strikes"},{"id":"11","name":"Sweeps"},{"id":"20","name":"Theory & Discussions"},{"id":"9","name":"Throws"},{"id":"31","name":"Wrestling"},{"id":"22","name":"Wrist Locks"}]}

但是当我尝试使用 PHP 进行解析时(PHP 代码和输出)

PHP 代码

<?php
$url = "https://domain.com/apis/cats.php?type=json";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json = curl_exec($ch);
$dcjsn = json_decode($json);

foreach ($dcjsn->categories as $cat){
echo $cat->id;
echo "<br>";
}

输出为:

555
15
14
554
13
23
26
25
27
17
30
29
18
28
20
9
22

平均缺少 10 件元素!

我未能识别代码中的错误。我也尝试过使用 file_get_contents() 但没有成功。

添加:

var_dump($json) 的结果

string(574) "{"categories":[{"id":"555","name":"Articles"},{"id":"15","name":"Crank"},{"id":"14","name":"Escapes"},{"id":"554","name":"Grappling Videos"},{"id":"13","name":"Guard Breaks"},{"id":"23","name":"Half Guard"},{"id":"26","name":"Japanese Jujutsu"},{"id":"25","name":"Leg Locks"},{"id":"27","name":"MMA"},{"id":"17","name":"Mount"},{"id":"30","name":"North South Position"},{"id":"29","name":"Self Defense"},{"id":"18","name":"Side Control"},{"id":"28","name":"Strikes"},{"id":"20","name":"Theory & Discussions"},{"id":"9","name":"Throws"},{"id":"22","name":"Wrist Locks"}]}"

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com