views:

151

answers:

4

Hi All,

    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?

A: 

I believe

'Jo''hn'

is the problem.

Cheers

Tom

Tom Bartel
yes ofcource the apostrophes is the problem. But i want to show the apostrophes also, what should i do?
subramani
So doesn't Ambrosia's technique with the double backslash do the trick, either?
Tom Bartel
A: 

The parser is choking on The 'Jo''hn' because of the single quote. Escape it with \'

axel_c
A: 

Try this

var jsonCallbackCode1 = eval("employees = { 'accounting' : [ { 'firstName' : 'Jo\'\'hn', 'lastName'  : 'Doe','age': 23 }]}");
    alert(employees.accounting[0].firstName);
c0mrade
Again its not working. Still have the same problem
subramani
+1  A: 

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.

Ambrosia