什么是格式化[像json这样的东西]?

时间:2012-07-11 10:34:32

标签: php javascript arrays json

我想开发一个从空中时间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数组?

4 个答案:

答案 0 :(得分:2)

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

中检查它

您可以使用json_decode($output, true);

将其转换为数组

答案 1 :(得分:1)

它似乎是json(只是摆脱了第一轮支架)。

您可以使用以下免费在线工具进行验证

http://jsonlint.com/

答案 2 :(得分:1)

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

答案 3 :(得分:1)

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