我正在写一个json语法,当我验证它时,我一直收到错误,
Parse error on line 6:
..."Dublin 1", { "produ
----------------------^
Expecting 'STRING'
我无法弄清楚错误的含义。
这是我的代码
{"invoice":
{"number":"1001",
"date":"21/02/2010",
"customer":"Joe Bloggs",
"address":"Dublin 1",
{"product details":
[
"name1":"Table",
"quantity1":"1",
"amount1":"250"
}
{
"name2":"Chair",
"quantity2":"6",
"amount2":"200"
}
]
}
}}
答案 0 :(得分:2)
JSON充满了键值对,所以我至少看到了三个问题。
1)"产品详情"对象需要一把钥匙。也许"产品详情"本来应该是关键?
2)您缺少产品详细信息数组值中第一个对象的开始{
。
3)您缺少分隔产品详细信息对象的逗号。
这是一些有效的json,可能是你想要的:
{
"invoice": {
"number":"1001",
"date":"21/02/2010",
"customer":"Joe Bloggs",
"address":"Dublin 1",
"product details": [
{
"name1":"Table",
"quantity1":"1",
"amount1":"250"
},
{
"name2":"Chair",
"quantity2":"6",
"amount2":"200"
}
]
}
}
使用此类JSON验证程序验证您的JSON: http://jsonformatter.curiousconcept.com/
答案 1 :(得分:0)
我强烈建议找一个好的Json编辑器。如果您使用C#,Java或其他类型的语言 考虑使用允许您生成Json的库。关键是,如果你手动组装JSON,你会有拼写错误,除非你关注细节:)
{
"invoice":
{
"number":"1001",
"date":"21/02/2010",
"customer":"Joe Bloggs",
"address":"Dublin 1",
"product details":
[
{
"name1":"Table",
"quantity1":"1",
"amount1":"250"
},
{
"name2":"Chair",
"quantity2":"6",
"amount2":"200"
}
]
}
}