Json Uncaught SyntaxError: Unexpected token ‘ Uncaught SyntaxError: Unexpected number

The unexpected number (index) error uses the JSON string, such as

var jsonStr = "{1:'Beijing note docket information',2:'Shanghai note docket information',3:'Guangdong note docket information',4:'Shenzhen note docket information 4',5:'Tianjin note docket information 5',6:'Hubei note docket information 6',7:'Chongqing note docket information 7',8:'EU note docket information 8',9:' California note docket information 8',10:'Canada Quebec note information',11:'Northeastern United States RGGI Association Organization',12:'Australia note information',13:'New Zealand note information',14:'Tokyo note information 11111',15:'Korea Seoul information',16:'Switzerland information note'}";

This string can be parsed normally with open source China and other json formatting, but jquery parsing errors do not recognize your set, so I had to look for errors.

Uncaught syntax error: unexpected token ‘error string, such as:

var jsonStr = "{'Beijing':1,'Shanghai':2,'Guangdong':3,'Shenzhen':4,'Tianjin':5,'Hubei':6,'Chongqing':7,'EU':8,'California':9,'Quebec, Canada':10,'RGGI, USA':11,'Australia':12,'New Zealand':13,'Tokyo':14,'Korea':15,'Switzerland':16}"

Using json formatting tool is also error-free, had to find jquery documentation to see jquery.parseJSON() usage . The example given is as follows.

Parsing a JSON string

jQuery Code:
var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.name === "John" ); I think it is the problem of single quotes and double quotes in it, now there is no other solution, so I have to change it by example, and the result is really successful. I think the jquery source code did not do the processing of the symbols inside the string to determine what kind of single quotes it contains.

If you find a solution to the problem, it’s easy to start

The JSON string is pieced together from the background, because the areaid is regarded as the key part, and the result is directly jsonstr. Append (‘”‘ + etsmapinfo. Getaeid() + ‘”); It turns 1 to 69. I don’t understand. But I next ruthless move just, outside first to turn into the string. Alas

I feel that solving problems first is the priority

The code in the string has a newline, and jQuery parsing will report an error just like what. You need to replace the newline symbol with a replacement function. As follows:

  var jsonStrRep = '${jsonStr}'.replace(/\r\n/g,"");
    jsonStrRep = jsonStrRep.replace(/\n/g,"");

Similar Posts: