我正在嘗試爲新項目實現主幹。還安裝了下劃線,requirejs,jquery和bootstrap。總的來說,它進展順利。我想將一些靜態調查問題數據合併到我的一個數據模型中。在調用外部文件時json中的'意外令牌'
{
"defaultOptions": {
"1": "Strongly Agree",
"2": "Somewhat Agree",
"3": "Have Mixed Feelings",
"4": "Somewhat Disagree",
"5": "Strongly Disagree",
"6": "Have No Opinion",
"7": "Do Not Wish To Respond"
},
"questions": {
"1": {
"question": "Question 1",
"options": {}
},
"2": {
"question": "Question 2",
"options": {}
},
"3": {
"question": "Question 3",
"options": {}
},
"4": {
"question": "Question 4",
"options": {}
},
"5": {
"question": "Question 5",
"options": {}
}
}
}
我目前沒有訪問我將最終使用來構建這個項目中的數據API,所以我目前正在關閉從這個項目的前一次迭代導出的一些虛擬的數據(這對美國選舉週期,所以每年都會發生)。我試圖從我正在使用的內容模型中提取一些靜態數據,並將其放入一個單獨的文件中,這樣就不會出現問題,我不必擔心無意中將其搞亂了。沒什麼大不了的,對吧?我沒有跨越任何域名,它們都位於同一臺服務器上。我有另一個數據集做同樣的事情。我甚至通過http://www.jsoneditoronline.org/運行信息以確保它是有效的json。
那麼問題是什麼?我在chrome中得到這個錯誤「Uncaught SyntaxError:Unexpected token:on line 2」,並且這個錯誤在FireFox'SyntaxError:missing;之前聲明「defaultOptions」:',指示器指向:defaultOptions之後。
我真的不知道爲什麼會發生這種情況。
我調用兩個JSON文件,一個右後外:
var survey = require('/elections/data/surveyQuestions.json');
var endorsements = require('/elections/data/endorsements.json');
的endorsements.json文件(和其他任何調用需要)沒有任何問題。這裏僅供參考:
[
"Abortion Rights Council",
"AFL-CIO",
"AFSCME",
"American Federation of Teachers",
"Building and Construction Trades Council",
"DFL Feminist Caucus",
"DFL Party",
"Education Minnesota",
"Freedom Club",
"GOP Feminist Caucus",
"Grassroots Party",
"Green Party of Minnesota",
"Independence Party",
"Libertarian Party of Minnesota",
"MAPE",
"Minnesota Citizens Concerned for Life",
"Minnesota Police and Peace Officers Association",
"National Association of Social Workers",
"Republican Party of Minnesota",
"Sierra Club",
"Stonewall DFL",
"TakeAction Minnesota",
"Taxpayers League of Minnesota",
"Teamsters DRIVE",
"United Auto Workers"
]
有沒有人有什麼想法,我失蹤了?
沒關係;我相信下面的答案是正確的。你試圖使用普通的JSON,就好像它是JavaScript一樣,這是行不通的。 – Pointy