2016-12-03 55 views
1

我在文件mock.json中有以下json。我試圖通過ajax調用它,但是,我收到此錯誤。錯誤:第1行解析錯誤:在json數據中

Error: Parse error on line 1: 
{ id: 1, name: 'My na 
--^ 
Expecting 'STRING', '}', got 'undefined' 

我用jsonlint驗證器來驗證json並獲取上述錯誤。我的JSON有什麼問題?

[{ 
    id: 1, 
    name: 'My name', 
    email: '[email protected]' 
}] 

回答

4

JSON standard描述字符串和字符串需要雙引號"性能。

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

所以你需要在JSON中作爲字符串的屬性和值的雙引號。

[{ 
    "id": 1, 
    "name": "My name", 
    "email": "[email protected]" 
}]