我正在尝试将以下字符串解析为JSON对象。它给了我错误。我找不到原因。
var json1 = "{'firstName': 'John','lastName': 'Smith', 'age': 25, 'address': {'streetAddress': '21 2nd Street','city': 'New York','state': 'NY', 'postalCode': '10021'}, 'phoneNumber': [ {'type': 'home','number': '212 555-1234'}, {'type': 'fax', 'number': '646 555-4567' }]}";
$.parseJSON(json1);
答案 0 :(得分:6)
对键和字符串值使用双引号"
:请参阅jsonlint
如果您使用双引号更改所有出现的单引号,则JSON有效。
答案 1 :(得分:0)
var json1 = '"result":[{"firstName": "John","lastName": "Smith", "age": 25, "address": [{"streetAddress": "21 2nd Street","city": "New York","state": "NY", "postalCode": 10021}, "phoneNumber": [ {"type": "home","number": 212 555-1234"}, {"type": "fax", "number": 6465554567 }]]}]";