问题
i have url with this simple JSON {"result":true,"data":[{"Position":"135"}]}
I tried to read it with this:
$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->result[1]->data->Position;
but it not works. Where i do a mistake? Thanks for helping!
回答1:
You are incorrectly addressing the data in the PHP object created from the JSON String
$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->data[0]->Position;
Or if there are more occurances
foreach ( $obj->data as $idx=>$data) {
echo $data->Position;
}
来源:https://stackoverflow.com/questions/41549153/read-json-values-from-url-via-php