我的API URL在浏览器中返回的代码,如下所示。但 json_decode($api_url,true);返回null。我检查了一下json_last_error();,它返回4(json错误语法)。它与json_decode(file_get_contents($api_url),true);为什么不与json_decode一起工作。请帮忙{"dataset":{"id":27153572,"dataset_code":"20MICRONS_A_DEBT","database_code":"DEB","name":"20 Microns Limited,Total Debt","description":"\u003cp\u003e20 Microns Limited(NSE:20MICRONS)-Total Debt(Annual)\u003c/p\u003e","refreshed_at":"2018-09-21T08:04:08.278Z","newest_available_date":"2018-03-31","oldest_available_date":"2005-03-31","column_names":["PERIOD","STANDALONE","CONSOLIDATED"],"frequency":"annual","type":"Time Series","premium":true,"limit":null,"transform":null,"column_index":null,"start_date":"2005-03-31","end_date":"2018-03-31","data":[["2018-03-31",128.56,133.68],["2017-03-31",144.9,151.73],["2016-03-31",155.18,163.41],["2015-03-31",152.8,164.62],["2014-03-31",162.01,176.64],["2013-03-31",148.49,164.73],["2012-03-31",144.67,158.6],["2011-03-31",81.42,120.31],["2010-03-31",84.35,87.35],["2009-03-31",58.62,58.62],["2008-03-31",46.52,null],["2007-03-31",42.46,null],["2006-03-31",40.03,null],["2005-03-31",38.98,null]],"collapse":null,"order":null,"database_id":14992}}
2 回答
慕容森
TA贡献1853条经验 获得超18个赞
您尝试执行的操作没有任何意义。$api_url
只是一个网址,因此当您尝试对其进行解码时,它没有json
结构,并且会抛出异常。
您应该解码的是该URL返回给您的数据。
所以首先您应该从url获取数据,然后使用json_decode($api_url,true);
。
要获取数据,您可以使用file_get_contents
或curl
。
- 2 回答
- 0 关注
- 185 浏览
添加回答
举报
0/150
提交
取消