我有一個簡單的JS表單,它接受一個搜索詞和一個下拉選項,並根據這些參數返回JSON數據。我相信我遇到的問題是即使intelliJ看到對另一個文件的引用,它也無法處理它('意外令牌錯誤')。JS從本地文件讀取JSON對象
jsFiddle JSON片段:本
var songs = [
{"title":"12-Bar Original" , "writer":"Lennon, McCartney, Harrison and Starkey ", "vocalist":"Instrumental "},
{"title":"Across the Universe" , "writer":"Lennon ", "vocalist":"Lennon "},
{"title":"Act Naturally" , "writer":"Russell, Morrison ", "vocalist":"Starkey "},
{"title":"Ain't She Sweet" , "writer":"Yellen, Ager ", "vocalist":"Lennon "},
{"title":"All I've Got to Do" , "writer":"Lennon ", "vocalist":"Lennon "},
{"title":"All My Loving" , "writer":"McCartney ", "vocalist":"McCartney "},
{"title":"All Things Must Pass" , "writer":"Harrison — — ", "vocalist":" "},
{"title":"All Together Now" , "writer":"McCartney, with Lennon ", "vocalist":"McCartney, with Lennon "},
{"title":"All You Need Is Love" , "writer":"Lennon ", "vocalist":"Lennon "},
{"title":"And I Love Her" , "writer":"McCartney, with Lennon ", "vocalist":"McCartney "}];
的思考?我確信我錯過了一些愚蠢的東西。欣賞眼睛。謝謝!
這是一個JS代碼,而不是JSON。你如何使用它?通過ajax或smth加載?如果是這樣,請刪除「var songs =」並尾隨「;」。 如果您想要運行JS代碼 - 例如添加一個全局變量「歌曲」,你可以評估文件的文字。您還可以將代碼修改爲模塊並通過RequireJS進行需求,或者只需將該文件加載到腳本標記中即可。 –
@PavelStaseljun - 不,它是完全有效的JSON。 – davidkonrad
Rly? JSON中的字符串「var songs =」代表什麼? –