1
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?

1
  • 1
    I think the problem rely on 'Jo''hn' see the double ' that break the string ;) Commented Nov 13, 2009 at 10:01

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

Try this

var jsonCallbackCode1 = eval("employees = { 'accounting' : [ { 'firstName' : 'Jo\'\'hn', 'lastName'  : 'Doe','age': 23 }]}");
    alert(employees.accounting[0].firstName);

Comments

0

I believe

'Jo''hn'

is the problem.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.