$result["success"]; // this fails --- how get success value

$result = json_decode(curl_exec($ch));	
var_dump($result);  // this makes below
echo "<br/>".$result["success"]; // this fails --- how get success value ???

object(stdClass)#1 (3) { ["success"]=> bool(false) ["challenge_ts"]=> string(20) "2016-12-06T18:14:46Z" ["hostname"]=> string(14) "yyyy.com" }

either by accessing the object’s property or by decoding the JSON into an array and not into an object.

1 Like

json_decode will parse a JSON string to an object. By passing a second parameter true to the function, it will be parsed as an array. So there are two possibilities:

$result = json_decode(curl_exec($ch));
echo $result->success;

or

$result = json_decode(curl_exec($ch), true);
echo $result['success'];

You can always read the full json_decode reference here: http://php.net/manual/en/function.json-decode.php

Good luck!

PS: debugging tip for the future; when var_dump’ing the variable, you can see it isn’t an array but an object of the class stdClass (the standard PHP class): object(stdClass).

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.