I’m using the Angel list api to pull this data and trying to parse it via this code (pull through attempted parse)
The Parsing code isn’t working properly and will not retrieve the value for [id] for some reason. I have been looking up json depth and think that may be the problem and have tried many different approaches but nothing seems to be working. Can someone assist in helping to pull individual values from the nested arrays?
$ch = curl_init($array_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$response = json_decode($data);
print $response->{'name'};
echo "\n";
Example Output
Array
(
[0] => Array
(
[id] => 79840
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/79840-e351f55eea90356818e586ca3e547981-thumb_jpg.jpg?buster=1333248008
[url] => https://angel.co/joinastartup-org
[name] => JoinAStartup.org
[type] => Startup
)
[1] => Array
(
[id] => 121425
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/121425-7cea796d5afc33877d68c633963ec8e9-thumb_jpg.jpg?buster=1353964843
[url] => https://angel.co/jointly
[name] => Jointly
[type] => Startup
)
[2] => Array
(
[id] => 76554
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/76554-d227b51eac3509eeba4cced14186b782-thumb_jpg.jpg?buster=1347923043
[url] => https://angel.co/supportlocal
[name] => SupportLocal
[type] => Startup
)
[3] => Array
(
[id] => 30334
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/30334-219f36ea273ef199c2aaf7b034554b90-thumb_jpg.jpg?buster=1326922125
[url] => https://angel.co/jointli
[name] => Jointli
[type] => Startup
)
[4] => Array
(
[id] => 14278
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/14278-8b9059bb1fa7fab5813dfbade19056eb-thumb_jpg.jpg?buster=1315736993
[url] => https://angel.co/joint
[name] => joint
[type] => Startup
)
[5] => Array
(
[id] => 22687
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/22687-94e1104706736e7636d23ff055819b8c-thumb_jpg.jpg?buster=1337954356
[url] => https://angel.co/join-our-talents
[name] => Join Our Talents
[type] => Startup
)
[6] => Array
(
[id] => 45059
[pic] =>
[url] => https://angel.co/joint-research-centre
[name] => Joint Research Centre
[type] => Startup
)
[7] => Array
(
[id] => 119433
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/119433-585159079dc0e8b31156e772d53914de-thumb_jpg.jpg?buster=1346721187
[url] => https://angel.co/joinspeaker-1
[name] => JoinSpeaker
[type] => Startup
)
[8] => Array
(
[id] => 40214
[pic] =>
[url] => https://angel.co/advanced-joining-technology
[name] => Advanced Joining Technology
[type] => Startup
)
[9] => Array
(
[id] => 35338
[pic] => https://s3.amazonaws.com/photos.angel.co/startups/i/35338-52ca618ccef71f1a67b21e2e838a4674-thumb_jpg.jpg?buster=1326845104
[url] => https://angel.co/joingo
[name] => Joingo
[type] => Startup
)
)
I think the question is why isn’t the print statement working? First, you have
<br>at end of every line, that’s not valid PHP syntax and I hope that’s not in your actual code.Second, regarding the print statement… response is an array, so you access it using:
Replace
0with the index of the element you want to access. You can even use a loop to iterate over the results and get all the namesYou can also use a foreach loop.