当我在浏览器上运行这个json文件时发现错误,我不知道为什么?
这是我的完整代码:
[
{
name: "Samsung Tab 3",
price: 500,
description:
"Samsung Tab 3 is very well "
+ "Samsung Tab 3 is very well ",
images: [
"images/tablet1.png",
"images/tablet1-thumb.png"
],
reviews: [
{
stars: 5,
body: "I Love this Tab",
author: "Michael.Gamel@hotmail.com"
},
{
stars: 1,
body: "this tab sucks",
author: "samir@hotmail.com"
}
],
processor: " Core™2 Duo",
ram: "1 GB",
colors: ["White","Red","Blue"],
canPurchase: true,
soldOut: false
}
,
{
name: "Apple iPad 4",
price: 500.50,
description:
"Apple iPad 4 is very well "
+ "Apple iPad 4 is very well ",
images: [
"images/tablet2.png",
"images/tablet2-thumb.png"
],
reviews: [
{
stars: 3,
body: "I Love this Tab",
author: "Michael.Gamel@hotmail.com"
},
{
stars: 4,
body: "this tab sucks",
author: "samir@hotmail.com"
}
],
processor: "core i3",
ram: "2 GB",
colors: ["Black", "Yellow", "Brown"],
canPurchase: true,
soldOut: false
}
]
我发现名称错误,我的浏览器告诉我:
错误:第2行的解析错误: [{name:" Samsung Tab 3 ----------------- ^ 期待' STRING'}'}'
这是什么意思?? !!答案 0 :(得分:1)
您需要引用属性名称才能使其有效json:http://json.org/example
答案 1 :(得分:0)
因为JavaScript字符串连接 像这样:
description : "Samsung Tab 3 is very well "
+ "Samsung Tab 3 is very well "
试试这个:
[{
name : "Samsung Tab 3",
price : 500,
description : "Samsung Tab 3 is very well " + "Samsung Tab 3 is very well ",
images : [
"images/tablet1.png",
"images/tablet1-thumb.png"
],
reviews : [{
stars : 5,
body : "I Love this Tab",
author : "Michael.Gamel@hotmail.com"
}, {
stars : 1,
body : "this tab sucks",
author : "samir@hotmail.com"
}
],
processor : " Core™2 Duo",
ram : "1 GB",
colors : ["White", "Red", "Blue"],
canPurchase : true,
soldOut : false
}, {
name : "Apple iPad 4",
price : 500.50,
description : "Apple iPad 4 is very well " + "Apple iPad 4 is very well ",
images : [
"images/tablet2.png",
"images/tablet2-thumb.png"
],
reviews : [{
stars : 3,
body : "I Love this Tab",
author : "Michael.Gamel@hotmail.com"
}, {
stars : 4,
body : "this tab sucks",
author : "samir@hotmail.com"
}
],
processor : "core i3",
ram : "2 GB",
colors : ["Black", "Yellow", "Brown"],
canPurchase : true,
soldOut : false
}]
以下是 Demo
答案 2 :(得分:0)
键名称...
周围缺少引号"name": "Samsung Tab 3",
这里的主要问题是 description 中的格式。您将遇到语法问题,如:
"Samsung Tab 3 is very well "
+ "Samsung Tab 3 is very well ",
同时查看JSONLint,这将有助于验证您的JSON。