Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解析JSON数组和检索PHP字符串变量?_Php_Arrays_Json_Curl - Fatal编程技术网

如何解析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;