Validation Result JSON URL

Asked

Viewed 28 times

-4

The following I am needing to search if certain series has been approved, if it is not approved do not let the user proceed. I need to get the information from a url, which brings the following result if the series is not approved {"serial": "281924406", "approved": false} if it is approved {"serial": "281924406", "approved": true}. See command

$url = "https://10.0.10.22/runin/clones/". $_POST["NUNOTA"] ." /approved/";

$result = json_decode(file_get_contents($url));

var_dump($resultado); 

The printed result is as follows: Object(stdClass)#1 (2) {["serial"]=string(9) "281924406" ["approved"]=>bool(false)}

How can I turn into a variable to make the validation?

1 answer

0


For example, you can access individual object items as follows:

$url = "https://10.0.10.22/runin/clones/". $_POST["NUNOTA"] ."/aprovada/";
$resultado = json_decode(file_get_contents($url));

if ($resultado->aprovada) {
echo "Serial " . $resultado->serial . "aprovada.";
} else {
echo "Serial " . $resultado->serial . "não aprovada.";
}

https://www.php.net/manual/en/sdo.sample.getset.php

  • It worked blz, thank you very much.

  • Good. If it worked mark the answer as useful. Vl

Browser other questions tagged

You are not signed in. Login or sign up in order to post.