duanhan4763 2016-01-09 17:13
浏览 53
已采纳

从PHP中的JSON解码数据中提取FIRST结果

I have a script:

$json_url = "https://blockchain.info/ticker";
$json = file_get_contents($json_url);
$json=str_replace('},

]',"}

]",$json);
$data = json_decode($json);

echo "$" . ($data->USD->last);

This works perfect!

Now I have a second version of this:

$json_url3 = "https://blockchain.info/da/unconfirmed-transactions?format=json";
$json3 = file_get_contents($json_url3);
$json3=str_replace('},

]',"}

]",$json3);
$data3 = json_decode($json3);
echo "Latest hash: " . ($data3->txs->hash) . "<br>";

Why does the send script not work? I have a $json2 running without any issues with another API call as well.

  • 写回答

2条回答 默认 最新

  • duanjunao9348 2016-01-09 17:47
    关注

    Variable txs is an array of objects.

    Your last line should be written as:

    echo "Latest hash: " . ($data3->txs[0]->hash) . "<br>";
    

    It outputs:

    Latest hash: fd37b1ddfbe08d485a62bb3aeb7c9088e7dd3a352ac9e9e8eb6f170a9b4210cd
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于博途V17进行仿真时无法建立连接问题
  • ¥15 请问下这个红框里面是什么文档或者记事本编辑器
  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)