我有这个网址:
http://server.com/api.php?results
{"Name":"Pit, Loka","Current":{"Item":"16","test":"test","test":"84","test":"ok"}}
我猜PHP示例是:
<?php
$file = file_get_contents("http://server.com/api.php?results=item");
$data = json_decode($file);
print_r($data);
?>
但我无法获得任何结果 我该如何解决这个问题?
答案 0 :(得分:0)
<?php
$file = file_get_contents("http://server.com/api.php?results=item");
$data = json_decode($file);
$name = $data->Name; // "Name":"Pit, Loka"
$current = $data->Current->Item; //"Current":{"Item":"16","test":"test","test":"84","test":"ok"}
foreach ($current as $currentX) {
echo $currentX->Item;
}
?>
它应该工作......请测试。