Uncaught SyntaxError: Unexpected token c in JSON at position 13
Uncaught SyntaxError: Unexpected token c in JSON at position 13
我有一个字符串 (var),我在 javascript 中解析为 JSON。但是一旦我这样做,我就会收到一条错误消息
Uncaught SyntaxError: Unexpected token c in JSON at position 13
var DL_response = {"result":"{"cov_details":[{"issue_date":"UNIT
OFFICE,NEYVELI","cov":"MCWG"}],"dl_number":"TN39Y20100000784","address":"PERIYA COLONY KO PAVAZHANGUDI
VIRUDHACHALAM TK","issue_date":"24-03-2020","dob":"21-03-1971","name":"VICNESWARAN
S","blood_group":"","validity":{"transport":"","non-transport":"24-03-2010 to 23-03-
2030"},"father_husband":"SELVARAJ"}","status-code":"101","request_id":"a9642ae9-2f10-4e9a-9f7e-
c3ee1a9a2dbe"}
var Driving_License = JSON.parse(DL_response);
可能导致此错误的原因是什么?是因为有什么特殊字符吗?
首先,您的JSON是无效的。其次,它不是 JSON 字符串,而是 JavaScript 对象本身。没有必要再次解析它。如果对象有效,您可以直接访问它而无需进一步解析。
这是我修正的数据。
var DL_response = {
"result":{
"cov_details":[
{
"issue_date":"UNIT OFFICE,NEYVELI",
"cov":"MCWG"
}
],
"dl_number":"TN39Y20100000784",
"address":"PERIYA COLONY KO PAVAZHANGUDI VIRUDHACHALAM TK",
"issue_date":"24-03-2020",
"dob":"21-03-1971",
"name":"VICNESWARANS",
"blood_group":"",
"validity":{
"transport":"",
"non-transport":"24-03-2010 to 23-03-2030"
},
"father_husband":"SELVARAJ",
"status-code":"101",
"request_id":"a9642ae9-2f10-4e9a-9f7e-c3ee1a9a2dbe"
}
}
console.log(DL_response.result.dob)
// output: 21-03-1971
我有一个字符串 (var),我在 javascript 中解析为 JSON。但是一旦我这样做,我就会收到一条错误消息
Uncaught SyntaxError: Unexpected token c in JSON at position 13
var DL_response = {"result":"{"cov_details":[{"issue_date":"UNIT
OFFICE,NEYVELI","cov":"MCWG"}],"dl_number":"TN39Y20100000784","address":"PERIYA COLONY KO PAVAZHANGUDI
VIRUDHACHALAM TK","issue_date":"24-03-2020","dob":"21-03-1971","name":"VICNESWARAN
S","blood_group":"","validity":{"transport":"","non-transport":"24-03-2010 to 23-03-
2030"},"father_husband":"SELVARAJ"}","status-code":"101","request_id":"a9642ae9-2f10-4e9a-9f7e-
c3ee1a9a2dbe"}
var Driving_License = JSON.parse(DL_response);
可能导致此错误的原因是什么?是因为有什么特殊字符吗?
首先,您的JSON是无效的。其次,它不是 JSON 字符串,而是 JavaScript 对象本身。没有必要再次解析它。如果对象有效,您可以直接访问它而无需进一步解析。
这是我修正的数据。
var DL_response = {
"result":{
"cov_details":[
{
"issue_date":"UNIT OFFICE,NEYVELI",
"cov":"MCWG"
}
],
"dl_number":"TN39Y20100000784",
"address":"PERIYA COLONY KO PAVAZHANGUDI VIRUDHACHALAM TK",
"issue_date":"24-03-2020",
"dob":"21-03-1971",
"name":"VICNESWARANS",
"blood_group":"",
"validity":{
"transport":"",
"non-transport":"24-03-2010 to 23-03-2030"
},
"father_husband":"SELVARAJ",
"status-code":"101",
"request_id":"a9642ae9-2f10-4e9a-9f7e-c3ee1a9a2dbe"
}
}
console.log(DL_response.result.dob)
// output: 21-03-1971