1

我想开发从广播时间 api 读取一些数据的网站。

它生成如下内容:

({"env":"production","schedulerTime":"2012-07-11 14:44:34","previous":{"name":"作者: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":"作者: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":"作者:Jalale Ale Ahmad - Modire Madrese [www.audiolib.ir]","开始":"2012-07-11 10:31:11.217571","结束":"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":"","开始":"2012-07-11 13:58:00","结束":"2012-07-11 16:00:00"}],"nextShow":[],"timezone":"IRDT", "timezoneOffset":"16200","AIRTIME_API_VERSION":"1.0"})"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" })"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 数组?

4

4 回答 4

2

它似乎是有效的 JSON ..在http://jsonlint.com/中检查它...

您可以使用将其转换为数组json_decode($output, true);

于 2012-07-11T10:38:31.327 回答
1

这绝对是 JSON。您只需跳过数据开头和结尾的圆括号。json_decode PHP 函数应该能够为您解码它。

于 2012-07-11T10:39:26.170 回答
1

它似乎是 json(只需去掉第一个圆括号)。

您可以使用下面的免费在线工具来验证它

http://jsonlint.com/

于 2012-07-11T10:37:39.167 回答
1

虽然它不是有效的 JSON,但它看起来像带有额外括号的 JSON。正如 Felix 所提到的,它可能是一个没有函数名的 JSON-P 打包响应。请查看 API 文档以了解如何提供它,或者,如果您可以在接收后和传递给 JSON.parse 之前对数据进行后处理,则只需()手动删除。

于 2012-07-11T10:56:25.380 回答