好吧,我使用coinbase'API来创建BTC的当前价格,但是当我尝试使用json_decode()时,它返回一个错误,导致我相信他们的响应不是JSON。为什么数组的类型是这样的?
https://coinbase.com/api/v1/prices/spot_rate?currency=USD
返回:
{"amount":"90.00","currency":"USD"}
我试图json_decode($ grabPrice); $ grabPrice等于该API的file_get_contets()。它给我的错误是:
Catchable fatal error: Object of class stdClass could not be converted to string in
如何获得PHP变量中的金额?
谢谢。
什么错误?据我所知,它是JSON。 –
我试过json_decode($ grabPrice); $ grabPrice等于该API的file_get_contets()。它给我的错误是:可捕获的致命错误:class stdClass的对象无法转换为 – user2594145
中的字符串,这是因为你试图打印返回的值,在这种情况下,它是一个对象....'echo $ returnedFromJsonDecode - >金额;'而不是 – Orangepill