Cannot understand JSON code

i haven’t studied javascript and i am directly doing jquery, so i am not able to understand what this code tells us. please elaborate the following

Q1.why value of var txt begin with single quote here? In JSON file i don’t think so this is the syntax.

var txt = '{ "employees" : [' +
'{ "firstName":"John" , "lastName":"Doe" },' +
'{ "firstName":"Anna" , "lastName":"Smith" },' +
'{ "firstName":"Peter" , "lastName":"Jones" } ]}';

Q2.why in the value " + txt + " is present? is this showing blank space then txt and then again space?

var obj = eval ("(" + txt + ")");

Hi there,

This doesn’t really have much to do with JSON, rather with string concatenation.
The txt variable is a string and begins with a single quote, so that the double quotes that occur within it don’t have to be escaped.
If you wrote it using double quotes, you would have to write:

var txt = "{ \\"employees\\" : [" +

and so on …

Q2.why in the value " + txt + " is present? is this showing blank space then txt and then again space?[/QUOTE]

We have already established that txt is a string and again, this is an example of string concatenation.
eval is passed a string as an argument, in this case a string consisting of a bracket, the variable txt and a closing bracket.

If it makes it any easier to understand, you could rewrite your example as:

part1 = "(";
part2 = txt;
part3 = ")"
string = part1 + part2 + part3;
eval(string);

Best thing to do is read this:
http://www.quirksmode.org/js/strings.html

and pay special attention to this bit:
http://www.quirksmode.org/js/strings.html#conc

We have already established that txt is a string and again, this is an example of string concatenation.
eval is passed a string as an argument, in this case a string consisting of a bracket, the variable txt and a closing bracket.

If it makes it any easier to understand, you could rewrite your example as:

part1 = "(";
part2 = txt;
part3 = ")"
string = part1 + part2 + part3;
eval(string);

Best thing to do is read this:
http://www.quirksmode.org/js/strings.html

and pay special attention to this bit:
http://www.quirksmode.org/js/strings.html#conc[/QUOTE]

Perfect answer…thanks a ton!