qvfps
asked on
PHP Curl Json issues
I am trying to write a small application in PHP do download some content using curl in json format and process it. Below is the data returned via curl and the error message I get when trying to walk through it. I am sure it is something small I have done wrong I just cant see it.
I appreciate any suggestions.
<?php
$url = "https://website/records";
$apikey = '11111111111111111111111';
$ch = curl_init( $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-KEY: ' .$apikey, 'Content-Type: application/json' , 'Accept: application/json'));
$myout = curl_exec($ch);
curl_close($ch);
//$result = json_decode(json_decode($m yout,true) );
$result = json_decode($myout);
echo $myout;
$myResult = $result;
foreach($myResult as $value){
echo $value->name . ", " , $value->gender . "<br>\n";
}
?>
{"items":[{"TicketID":41," WorkHoursI D":53,"Sta rtWorkHour ":"2019-09 -16T13:33: 11Z","EndW orkHour":" 2019-09-16 T13:33:13Z ","Technic ianContact ID":2,"Bil liable":tr ue,"OnCust omerSite": false,"Des cription": null,"Tech nicianFull Name":"Tec h1","Techn icianEmail ":"Tech1@s upport.com "},{"Ticke tID":41,"W orkHoursID ":82,"Star tWorkHour" :"2019-08- 05T15:23:2 1Z","EndWo rkHour":"2 019-08-05T 15:26:33Z" ,"Technici anContactI D":7,"Bill iable":tru e,"OnCusto merSite":f alse,"Desc ription":n ull,"Techn icianFullN ame":"Tech 2","Techni cianEmail" :"Tech2@su pport.com" }],"totalI temCount": 2,"page":1 ,"itemsInP age":10,"t otalPages" :1,"prevLi nk":"","ne xtLink":"" }
Invalid argument supplied for foreach()
I appreciate any suggestions.
<?php
$url = "https://website/records";
$apikey = '11111111111111111111111';
$ch = curl_init( $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-KEY: ' .$apikey, 'Content-Type: application/json' , 'Accept: application/json'));
$myout = curl_exec($ch);
curl_close($ch);
//$result = json_decode(json_decode($m
$result = json_decode($myout);
echo $myout;
$myResult = $result;
foreach($myResult as $value){
echo $value->name . ", " , $value->gender . "<br>\n";
}
?>
{"items":[{"TicketID":41,"
Invalid argument supplied for foreach()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help