0

我正在编写一个 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": [
            ]
        }
     ]
}
4

2 回答 2

4

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

{
    "document": {
        "2009": [
            ...
        ]
    }
}
于 2013-04-12T06:56:00.603 回答
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": [
        ]
    }
 ]
 }
 ]
 **}**

核实。你明白我的意思了吗?

于 2013-04-12T07:00:04.717 回答