什么错误在我的json文件


What fault in my json file?

我有一个json文件,名为:openingstijden。json

{
    "openingstijden": {
        "normaal": {
            ["10.00", "18.00"],
            ["8.00", "16.00"],
            ["8.00", "18.00"],
            ["8.00", "18.00"],
            ["8.00", "18.00"],
            ["8.00", "18.00"],
            ["8.00", "18.00"]
        },
        "speciaal": {
            "2013-11-20": ["12.00", "20.00"]
        }
    }
}

但是当我试图对这个数组

进行vardump时
// path naar config file
define('CONFIG_FILE', __DIR__.'/openingstijden.json');
$businessHours = json_decode(file_get_contents(CONFIG_FILE), true);
var_dump($businessHours); 

我得到这个结果:NULL当我尝试对数组进行遍历时:警告:为foreach()提供了无效参数

你们知道我的json文件有什么问题吗?

提前感谢!

您的JSON字符串无效。有效JSON中的每个条目必须有一个值的键。以["10.00", "18.00"],开头的七行不像"2013-11-20": ["12.00", "20.00"]那样有键。

{
    "openingstijden": {
        "normaal": {
            "0": ["10.00", "18.00"],
            "1": ["8.00", "16.00"],
            "2": ["8.00", "18.00"],
            "3": ["8.00", "18.00"],
            "4": ["8.00", "18.00"],
            "5": ["8.00", "18.00"],
            "6": ["8.00", "18.00"]
        },
        "speciaal": {
            "2013-11-20": ["12.00", "20.00"]
        }
    }
}

如果您不想为"正常"值使用键,则可以将{}替换为[]。在这种情况下,你有一个可以通过键" normal "访问的数组,其中包含数组。