【发布时间】:2021-12-22 17:15:26
【问题描述】:
我尝试使用基本的、少量的参数。 JSON 代码,没有任何问题。
但现在我需要使用这个“高级”JSON,我有点迷路了
{
"code":"success",
"username":"x",
"nodes":[
{
"id":"68",
"time":987
},
{
"id":"69",
"time":987
}
]
}
当我尝试使用之前的代码将值放入 PHP 变量时,我无法获得 ID 和 TIME、CODE 和 SUCCESS 没有问题。
我使用的PHP代码:
$url = "example.com";
$url = str_replace(" ","%20",$url);
$json = @file_get_contents($url);
$details = json_decode($json, TRUE);
// print_r($details);
echo $details[code];
谢谢你们!
【问题讨论】:
-
这能回答你的问题吗? How to access JSON decoded array in PHP
-
echo $details['nodes'][0]['id']; -
谢谢!这是工作。请问您,我如何计算和打印出总数组的数量? "nodes":[ { "id":"68", "time":987 }, { "id":"69", "time":987 } ] 在这种情况下,我想得到数字 2