我想开发一个从空中时间api读取一些数据的网站。
它产生如下内容:
({"env":"production","schedulerTime":"2012-07-11 14:44:34","previous":{"name":"Written By: Jalale Ale Ahmad - Modire Madrese [www.audiolib.ir]","starts":"2012-07-11 09:30:48.228571","ends":"2012-07-11 10:01:00.087571","type":"track"},"current":{"name":"Written By: Jalale Ale Ahmad - Modire Madrese [www.audiolib.ir]","starts":"2012-07-11 10:01:00.087571","ends":"2012-07-11 10:31:11.217571","media_item_played":true,"record":0,"type":"track"},"next":{"name":"Written By: Jalale Ale Ahmad - Modire Madrese [www.audiolib.ir]","starts":"2012-07-11 10:31:11.217571","ends":"2012-07-11 11:01:17.567071","type":"track"},"currentShow":[{"start_timestamp":"2012-07-11 13:58:00","end_timestamp":"2012-07-11 16:00:00","name":"Untitled Show","id":36,"instance_id":36,"record":0,"url":"","starts":"2012-07-11 13:58:00","ends":"2012-07-11 16:00:00"}],"nextShow":[],"timezone":"IRDT","timezoneOffset":"16200","AIRTIME_API_VERSION":"1.0"})
它不是JSON,那是什么?我应该如何将其转换为php或javascript数组?
答案 0 :(得分:2)
它似乎是有效的JSON ..在http://jsonlint.com/ ...
中检查它您可以使用json_decode($output, true);
答案 1 :(得分:1)
答案 2 :(得分:1)
绝对是JSON。您只需跳过数据开头和结尾的圆括号即可。 json_decode PHP函数应该能够为你解码它。
答案 3 :(得分:1)
虽然它不是有效的JSON,但它看起来像JSON,周围有额外的括号。正如Felix所提到的,可能是没有函数名称的JSON-P打包响应。检查有关如何提供它的API文档,或者如果您可以在接收之后和传递给JSON.parse之前对数据进行后处理,只需手动删除()
。