Read JSON values from URL via PHP

前端 未结 1 429
猫巷女王i
猫巷女王i 2021-01-15 22:55

i have url with this simple JSON {\"result\":true,\"data\":[{\"Position\":\"135\"}]}

I tried to read it with this:

$json = file_get_cont         


        
相关标签:
1条回答
  • 2021-01-15 23:56

    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;
    }
    
    0 讨论(0)
提交回复
热议问题