I am using curl to return json data from a service. The var dump works fine, however when i try to access a key value pair i get nothing? One of the keys is status, which is what i am trying to retrieve in my if statement.
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_USERAGENT, '$AgentString');
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_HTTPHEADER,array (
"Accept: application/json"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
$json = json_decode(utf8_encode($result), true);
var_dump($json["return"]);
if (isset($json->status)) {
// do something
print("yes");
} else {
print("No");
}
Since the second parameter in
json_decodeis true, the result would be returned as an associative array.Should be