Reputation: 1069
var jsonCallbackCode1 = eval("employees = { 'accounting' : [ { 'firstName' : 'Jo''hn', 'lastName' : 'Doe','age': 23 }]}");
alert(employees.accounting[0].firstName);
I got the following exception
Microsoft JScript compilation error: Expected '}'
help me?
Upvotes: 1
Views: 1653
Reputation: 2592
Try this... you have to use two backslashes to escape fully:
var jsonCallbackCode1 = eval("employees = { 'accounting' : [ { 'firstName' : 'Jo\\'\\'hn', 'lastName' : 'Doe','age': 23 }]}");
alert(employees.accounting[0].firstName);
Or of course you could just remove the apostrophes from the firstName altogether.
Upvotes: 1
Reputation: 22948
Try this
var jsonCallbackCode1 = eval("employees = { 'accounting' : [ { 'firstName' : 'Jo\'\'hn', 'lastName' : 'Doe','age': 23 }]}");
alert(employees.accounting[0].firstName);
Upvotes: 0
Reputation: 6796
The parser is choking on The 'Jo''hn' because of the single quote. Escape it with \'
Upvotes: 0