json有不同的子格式吗?

时间:2014-08-07 19:21:08

标签: php json

这个JSON是否被破坏或者它有不同的格式?

如果是,那是什么格式?

如果不是,为什么json_decode不能用于此?它返回一个空数组。

http://www.mackolik.com/AjaxHandlers/ProgramDataHandler.ashx?type=6&sortValue=DATE&week=14062&day=-1&sort=-1&sortDir=1&groupId=-1&np=0&sport=1

3 个答案:

答案 0 :(得分:1)

格式不正确。此工具将为您纠正它。转到此处:http://jsonformat.com/#jsondataurllabel

复制你的json并让它解析。

答案 1 :(得分:0)

此正则表达式解决了您的问题:

j = re.sub(r"{\s*(\w+):", r'{"\1":', j)
j = re.sub(r",\s*(\w+):", r',"\1":', j)
j = j.replace("'", '"')

答案 2 :(得分:0)

如果安装了PEAR Services_JSON包,并且在include路径中,它将正确解析您的文件,而无需修改源JSON:

<?php

$my_file = file_get_contents('http://www.mackolik.com/AjaxHandlers/ProgramDataHandler.ashx?type=6&sortValue=DATE&week=14062&day=-1&sort=-1&sortDir=1&groupId=-1&np=0&sport=1');

$json = new Services_JSON();

$decoded = $json->decode($my_file);

print_r($decoded);