我正试图解析从下面的URL JSON。但是,当我运行var_dump(json_decode($result, true))
时,它返回NULL。但是当我复制echo $item_url
的URL时,它会返回正确的JSON。试图使用cURL来解析JSON-var_dump返回NULL
我已阅读的另一个问题是var_dump(json_decode($result, true));
将返回与空格的字符串,并且可能是一个问题
$item_url = "http://steamcommunity.com/market/priceoverview/?country=US¤cy=1&appid=730&market_hash_name=" . $rgDescriptions->market_hash_name;
echo $item_url;
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, urlencode($item_url));
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$result = curl_exec($curl_handle);
curl_close($curl_handle);
var_dump(json_decode($result, true));
贝娄是,可能会通过一个URL的一个例子。
检查这个回答类似的问题:http://stackoverflow.com/questions/16700960/how-to-use-curl-to-get-json-data-and-decode-the-data – spaniard
这里第二个参数可能是问题;试试这个var_dump(json_decode($ result)); – itzmukeshy7