在PHP中,可以使用以下方法来获取JSON数据:
$url = 'example.json'; $json = file_get_contents($url); $url = 'example.json'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $url = 'example.json'; $options = array( 'http' => array( 'method' => 'GET', 'header' => 'Content-type: application/x-www-form-urlencoded', ), ); $context = stream_context_create($options); $json = file_get_contents($url, false, $context); 以上是获取JSON数据的几种常见方法,可以根据实际需求选择合适的方法来使用。