如何在php中获取对象的值?

当我尝试获取对象值时,我遇到了问题。但是当我只是回显对象时,没有null我不知道如何获取该值

if(isset($_POST['submit'])) {

    $secret = "6Le3nvgUAAAAAMU0DRNLtvtaIq3h6X9ybEnO_txv";
    $captcha = $_POST['g-recaptcha-response'];
    $url = 'https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$captcha;

    $response = file_get_contents($url);


    echo $response;


}

我得到了回应

enter image description here

但是当我尝试$ response->成功时。它返回null ..

评论
  • 田又青
    田又青 回复

    The response you 've got is written in JavaScript Object Notation (JSON). For this purpose PHP got it 's own JSON decode and encode functions.

    $decodedResponse = json_decode($response);
    var_dump($decodedResponse->success);