Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
    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?

share|improve this question
1  
I think the problem rely on 'Jo''hn' see the double ' that break the string ;) –  kentaromiura Nov 13 '09 at 10:01
add comment

4 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Try this

var jsonCallbackCode1 = eval("employees = { 'accounting' : [ { 'firstName' : 'Jo\'\'hn', 'lastName'  : 'Doe','age': 23 }]}");
    alert(employees.accounting[0].firstName);
share|improve this answer
1  
Again its not working. Still have the same problem –  subramani Nov 13 '09 at 11:31
add comment

I believe

'Jo''hn'

is the problem.

share|improve this answer
    
yes ofcource the apostrophes is the problem. But i want to show the apostrophes also, what should i do? –  subramani Nov 13 '09 at 14:14
    
So doesn't Ambrosia's technique with the double backslash do the trick, either? –  Tom Bartel Nov 17 '09 at 17:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.