2016-12-03 1789 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]" 
}]