好吧,我认为我能够轻松地做到这一点,但我无法想象如何。 我曾经在很多方面尝试过这里和其他页面,但没有任何作用;我花了两天时间,但最后我决定在这里注册并询问。
所以这是我的业力:
http://api.bitcoinvenezuela.com/DolarToday.php?json=yes
该url生成此json:
{" _antibloqueo&#34 ;: {"移动":" HTTPS://dt.wordssl.net","视频":& #34;"" corto_alternativo":" HTTPS://bit.ly/venezuela911"," enable_iads":"&#34 ;," enable_admobbanners":"为ca-app-PUB-1946229161分之8212448379596570"" enable_admobinterstitials":""" alternativo":" 68747470733a2f2f64626d7a647431663034653531632e636c6f756466726f6e64742e6e6574"" alternativo2":" 68747470733a2f2f64626d7a647431663034653531632e636c6f756466726f6e64742e6e6574""通知":" https://开头d3c134ru0r3b0g .cloudfront.net"," resource_id":" 33504 A"}," _labels":{" a":&#34 ; DOLARTODAY"," a1":" DOLAR CUCUTA"," b":" IMPLICITO"," c&#34 ;:" DICOM"," d":" DOLAR BITCOIN"," e":" DIPRO"},& #34; _timestamp":{" epoch":" 1513837984 "," fecha":" Diciembre 21 ,2017 02:33 AM& #34;," fecha_corta":" Dic 21,2017"," fecha_corta2":" Dic 2017"," fecha_nice&# 34;:" Diciembre 21,2017"," dia":" Jueves"," dia_corta":" Jue" }," USD" {" transferencia":的 121205.72 下," transfer_cucuta":121205.72"侮辱和不尊重&#34 ;: 10330.84," efectivo_real":122608.7," efectivo_cucuta":122608.7," promedio":121205.72" promedio_real":11311" cencoex":10," sicad1":94496.22," sicad2":11311" bitcoin_ref":94496.22," localbitcoin_ref":94496.22 " dolartoday":121205.72}" EUR" {" transferencia":143581.51" transfer_cucuta":143581.51"侮辱和不尊重& #34;:12259.61," efectivo_real":145502.19" efectivo_cucuta":145502.19" promedio":143581.51" promedio_real":13422.76, " cencoex":11.87" sicad1":112138.66" sicad2":13422.76," dolartoday":143581.51}" COL& #34 ;:{"侮辱和不尊重":0.023,"传递":0.023," compra":0.023,"本塔":0.02},&# 34; GOLD" {"速率":1265.9}" USDVEF" {"速率":10.02959}" USDCOL" :{" setfxsell":2820," setfxbuy":2740,"速率":3606," ratecash":2825," ratetrm":3005.76" trmfactor":0.2" trmfactorcash":0.06}" EURUSD" {"速率":1.18672 }," BCV":{" fecha":" 1513569600"," fecha_nice":" Diciembre 18,2017" " liquidez":" 100.643.049.794""饭店预订":" 9.742.000"}" MISC&#34 ;:{" PETROLEO":" 56,14""饭店预订":" 9,7"}} *
我需要读取它生成的json来获取粗体值(我需要的只有2个值);我尝试过curl,file_get_contents和许多其他方法,但没有任何作用。
基本上,我无法理解为什么这段代码不起作用:
<?php
$url = 'http://api.bitcoinvenezuela.com/DolarToday.php?json=yes';
$obj = json_decode(file_get_contents($url), true);
echo $obj;
?>
我收到警告:
警告:file_get_contents(http://api.bitcoinvenezuela.com/DolarToday.php?json=yes):无法打开流:第3行/home/u704982448/public_html/lbapi.php中的连接超时
知道这里发生了什么吗?失败在哪里?
编辑:看起来这里的问题是我的服务器IP被阻止了。对此有何解决方法?
感谢大家。
答案 0 :(得分:0)
您正试图在array
语句中打印echo
,因此出错。
<?php
$url = 'http://api.bitcoinvenezuela.com/DolarToday.php?json=yes';
$obj = json_decode(file_get_contents($url), true);
echo "<pre>";
print_r($obj);
?>
关于connection timeout
,您需要检查IP块等
答案 1 :(得分:0)
对我来说很好。
我在我的网页上测试过它,效果很好
只需要用var_dump()替换echo。
http://www.hoppvader.nu/Mail/test.php
print (df.index)
DatetimeIndex(['2017-06-25 00:31:53.993000', '2017-06-25 00:32:31.224000',
'2017-06-25 00:33:11.223000', '2017-06-25 00:33:53.876000',
'2017-06-25 00:34:31.219000', '2017-06-25 00:35:12.634000'],
dtype='datetime64[ns]', name='timestamp', freq=None)
df.index = df.index.round('1s')
print (df)
lon lat heading
timestamp
2017-06-25 00:31:54 48.1254 17.1458 a
2017-06-25 00:32:31 48.1254 17.1458 a
2017-06-25 00:33:11 48.1254 17.1458 a
2017-06-25 00:33:54 48.1254 17.1458 a
2017-06-25 00:34:31 48.1254 17.1458 a
2017-06-25 00:35:13 48.1254 17.1458 a
要回显您需要的两个值,请使用以下代码:
$url = 'http://api.bitcoinvenezuela.com/DolarToday.php?json=yes';
$obj = json_decode(file_get_contents($url), true);
var_dump($obj);
答案 2 :(得分:0)
似乎是服务器端的连接问题。也许有一些防火墙配置或服务器没有连接到互联网等...
您应该尝试以下操作,登录服务器并尝试运行:
curl http://api.bitcoinvenezuela.com/DolarToday.php?json=yes
此命令基本上会尝试访问url并打印输出。
如果您在此处遇到相同的超时问题,那么您可以证明错误与您的php脚本无关。