2016-12-08 63 views
-3
var bio = { 
    "name": "Belphy Baby", 
    "role": "student", 
    "contacts": { 
     "mobile": "9567166100", 
     "email": "[email protected]", 
     "github": "belphy16", 
     "location": "kottayam" 
    }, 
    "welcome message": "and miles to go before i sleep", 
    "skills": ["leadership", "enthusiastic", "learning"], 
    "bioPic": "images/fry.jpg" 
} 

$("#main").append(bio); 

結果錯誤:如何擺脫json中的這個分析錯誤?

Parse error on line 1: var bio = { "name": ^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

+2

請始終發佈代碼本身,而不是代碼圖片。 – Jim

+0

JSON沒有'var'關鍵字,變量或賦值運算符。那些表明片段是JavaScript。而且,JSON解析器不理解JavaScript。 –

+0

我不知道爲什麼你試圖追加一個JSON,但肯定沒有在這個https://jsfiddle.net/kqf6ywzz/或https://jsfiddle.net/kqf6ywzz/1/錯誤我想如果你想來顯示你的json使用html的jQuery的innerHTML的javascript append用於追加HTML元素 –

回答

1

輸入應該只是在JSONLint.com

{ 
    "name": "Belphy Baby", 
    "role": "student", 
    "contacts": { 
     "mobile": "9567166100", 
     "email": "[email protected]", 
     "github": "belphy16", 
     "location": "kottayam" 
    }, 
    "welcome message": "and miles to go before i sleep", 
    "skills": ["leadership", "enthusiastic", "learning"], 
    "bioPic": "images/fry.jpg" 

} 

編輯JSON:

答案是基於OP的first revision。請注意他提供的image

他得到的錯誤來自網站的JSON驗證服務的濫用。
正如該服務的名稱所暗示的,它驗證了JSON文件的語法。

我們的OP代碼包含JavaScript提示。如果在JSONLint輸入,它會給我們他的錯誤;指出應該是JSON輸入有錯誤。