如何解析JSON数组和检索PHP字符串变量?
好的。。。到目前为止,以下工作已经完成:如何解析JSON数组和检索PHP字符串变量?,php,arrays,json,curl,Php,Arrays,Json,Curl,好的。。。到目前为止,以下工作已经完成: // Open connection $ch = curl_init(); // Make the curl call curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: applicati
// Open connection
$ch = curl_init();
// Make the curl call
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$head = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($head, true);
foreach($data['events'] as $key => $item) {
// $event_id = $data['events'][$key]['eventId'];
$event_id = $item['eventId'];
// $name = $data['events'][$key]['name'];
$name = $item['name'];
// $desc = $data['events'][$key]['description'];
$desc = $item['description'];
echo "ID: $event_id<br>
NAME: $name<br>
DESCRIPTION: $desc<br>
<br>";
}
我想使用数据作为PHP字符串变量,这些变量可以在“primaryImage”、“categories”、“location”等元素中找到。应该是这样的:
echo $item['primaryImage']->smallImageUrl;
不幸的是,这不起作用。在这种情况下,它应该显示警告。收到任何警告?或者,再次尝试将其放入json_解码中
echo $item['primaryImage']->smallImageUrl;