2017-10-11 110 views
1

所以这里是我的。我需要的是2张专辑,至少4首歌。 专辑应包括:专辑名称,艺术家姓名,发行年份。 歌曲信息应该包括:歌曲标题,游戏时间我想用JSON存储音乐专辑

歌曲应该表示为对象阵列(ARRAY of OBJECTS)。

到目前为止,这些都是我的代码相册。我认为这是不正确的,但我不知道如何解决它。当我通过JSON检查运行它,它给了我错误

album1 = { 
"title" : "The Avairy”, 
"artist" : "Galantis”, 
"year_released" : 2017, 
“songs”:[{ 
    "song1” : "Hey Alligator”, 
    "songtime1” : 197, 
    “song2” : “True Feeling”, 
    “songtime2”: 214, 
    “song3” : “Written in the scars” 
    “songtime3” : 194, 
    “song4” : “No Money” 
    “songtime4” : 185; 
    }] 
} 

album2 = { 
    "title" : “Kolony”, 
    "artist" : “Steve Aoki”, 
    "year_released" : 2017, 
    “songs”:[ 
     "song1” : “Lit”, 
     "songtime1” : 150, 
     “song2” : “Without you”, 
     “songtime2”: 207, 
     “song3” : “Been Ballin” 
     “songtime3” : 180, 
     “song4” : “How Else” 
     “songtime4” : 152; 
    ] 
} 
+0

什么是错误?我看到您使用了错误的报价类型。 –

+0

错误:解析在线路错误1: album1 = {\t“标题”: 这是我下车蝙蝠 –

+1

如上所述,不正确引用该错误,并且你的歌属性是包含在一个单一的对象的阵列第一张专辑,并在第二个语法错误 – Steve

回答

1

你必须与你的JSON格式的各种问题:

  • 不应该有分号

  • 有中的对象缺少逗号

  • 你有一些奇怪的双引号(未常规"

你可以使用例如https://jsonlint.com/来验证你的json。

{ 
 
\t "title": "The Avairy", 
 
\t "artist": "Galantis", 
 
\t "year_released": 2017, 
 
\t "songs": [{ 
 
\t \t "song1": "Hey Alligator", 
 
\t \t "songtime1": 197, 
 
\t \t "song2": "True Feeling", 
 
\t \t "songtime2": 214, 
 
\t \t "song3": "Written in the scars", 
 
\t \t "songtime3": 194, 
 
\t \t "song4": "No Money", 
 
\t \t "songtime4": 185 
 
\t }] 
 
} 
 

 
{ 
 
\t "title": "Kolony", 
 
\t "artist": "Steve Aoki", 
 
\t "year_released": 2017, 
 
\t "songs": [{ 
 
\t \t "song1": "Lit", 
 
\t \t "songtime1": 150, 
 
\t \t "song2": "Without you", 
 
\t \t "songtime2": 207, 
 
\t \t "song3": "Been Ballin", 
 
\t \t "songtime3": 180, 
 
\t \t "song4": "How Else", 
 
\t \t "songtime4": 152 
 
\t }] 
 
}

BTW我找到建模专辑数据的这种方式很奇怪。为什么不能是这样的:

[{ 
 
\t "title": "The Avairy", 
 
\t "artist": "Galantis", 
 
\t "year_released": 2017, 
 
\t "songs": [{ 
 
\t \t \t "title": "Hey Alligator", 
 
\t \t \t "length": 197 
 
\t \t }, 
 
\t \t { 
 
\t \t \t "title": "True Feeling", 
 
\t \t \t "length": 214 
 
\t \t }, 
 
\t \t { 
 
\t \t \t "title": "Written in the scars", 
 
\t \t \t "length": 194 
 
\t \t }, 
 
\t \t { 
 
\t \t \t "title": "No Money", 
 
\t \t \t "length": 185 
 
\t \t } 
 
\t ] 
 
}, { 
 
\t "title": "Kolony", 
 
\t "artist": "Steve Aoki", 
 
\t "year_released": 2017, 
 
\t "songs": [{ 
 
\t \t \t "title": "Lit", 
 
\t \t \t "length": 150 
 
\t \t }, 
 
\t \t { 
 
\t \t \t "title": "Without you", 
 
\t \t \t "length": 207 
 
\t \t }, 
 
\t \t { 
 
\t \t \t "title": "Been Ballin", 
 
\t \t \t "length": 180 
 
\t \t }, 
 
\t \t { 
 
\t \t \t "title": "How Else", 
 
\t \t \t "length": 152 
 
\t \t } 
 
\t ] 
 
}]

+1

好吧,我们都从某个地方开始。用这种方式来看待它比我拥有的方式更有意义。 –

0

您应该使用“的而不是‘或无处不在JSON,除非它是内部串那样

json = { 
    "title": "Title is “Without you”", 
    "artist": "“Steve Aoki”" 
}; 

在专辑2中,你有“歌曲”声明为数组,但你使用它像一个对象。你也有分号内json这是错误的,失去分号后变量声明和失踪昏迷。正确的代码应该看起来像那样(我' m g艾尔文只有album1,做album2自己学习的东西):

album1 = { 
"title" : "The Avairy", 
"artist" : "Galantis", 
"year_released" : 2017, 
"songs":[{ 
    "song1" : "Hey Alligator", 
    "songtime1" : 197, 
    "song2" : "True Feeling", 
    "songtime2": 214, 
    "song3" : "Written in the scars", 
    "songtime3" : 194, 
    "song4" : "No Money", 
    "songtime4" : 185 
    }] 
}; 

如果你想成为你一定要非常小心一种高精度程序员。即使有这么多的语法错误,你也不会编写简单的函数。

+0

在这种情况下,专辑名称是kolony。它应该看起来像这样吗? json = { “title”:“Title is”Kolony“”, “artist”:“”Steve Aoki“”, “year”:2017 }; –

+0

这只是一个例子。不要把所有东西都明确地表示出来:) – ElChupacabra

0

对象的数组建议多单。你想要这个结构,而不是:

{ 
    "title" : "Kolony", 
    "artist" : "Steve Aoki", 
    "year_released" : 2017, 
    "songs":[ 
    { 
     "song" : "Lit", 
     "songtime" : 150 
    }, 
    { 
     "song" : "Without you", 
     "songtime" : 270 
    }, 
    { 
     "song" : "Been Ballin", 
     "songtime" : 180 
    }, 
    { 
     "song" : "How Else", 
     "songtime" : 152 
    } 
    ] 
} 

我也注意到不应该在那里和分歧引号的分号。并且您需要始终使用“and not”或“。

相关问题