通过 PHP 从 URL 读取 JSON 值

Read JSON values from URL via PHP

我有 url 这个简单的 JSON {"result":true,"data":[{"Position":"135"}]}

我试着用这个来阅读它:

$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->result[1]->data->Position;

但它不起作用。我在哪里做错了?感谢您的帮助!

您错误地寻址了从 JSON 字符串

创建的 PHP 对象中的数据
$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->data[0]->Position;

或者如果出现更多次

foreach ( $obj->data as $idx=>$data) {
    echo $data->Position;
}