无效的JSON错误

时间:2013-04-12 06:50:45

标签: json

我正在编写一个json文件,但是当我尝试在线验证时,我遇到了错误。代码有什么问题?

"document":
{

    "2009":
    [
        {
            "id": 1,
            "name": "2009 Annual Report",
            "version": 2,
            "timestamp": 1222222,
            "sessions": [
            ]
        },
        {
            "id": 10,
            "name": "2009 Annual Report",
            "version": 2,
            "timestamp": 1222222,
            "sessions": [
            ]
        }
     ],

    "2010":
    [
        {
            "id": 2,
            "name": "2010 Annual Report",
            "version": 2,
            "timestamp": 1222222,
            "sessions": [
            ]
        }
     ],
    "2011":
    [
        {
            "id": 1,
            "name": "2011 Annual Report",
            "version": 2,
            "timestamp": 1222222,
            "sessions": [
            ]
        }
     ]
}

2 个答案:

答案 0 :(得分:4)

即使是顶级对象也必须以大括号开头和结尾:

{
    "document": {
        "2009": [
            ...
        ]
    }
}

答案 1 :(得分:0)

你只是忘了把花括号放在数组的开头。 现在你的代码看起来像。

**{**
  "document":
 [

 { "2009":
 [
    {
        "id": 1,
        "name": "2009 Annual Report",
        "version": 2,
        "timestamp": 1222222,
        "sessions": [
        ]
    },
    {
        "id": 10,
        "name": "2009 Annual Report",
        "version": 2,
        "timestamp": 1222222,
        "sessions": [
        ]
    }
 ],

"2010":
[
    {
        "id": 2,
        "name": "2010 Annual Report",
        "version": 2,
        "timestamp": 1222222,
        "sessions": [
        ]
    }
 ],
"2011":
[
    {
        "id": 1,
        "name": "2011 Annual Report",
        "version": 2,
        "timestamp": 1222222,
        "sessions": [
        ]
    }
 ]
 }
 ]
 **}**

检查一下。你明白了我的意思吗?