views:

42

answers:

1
dynamictextareas.push({guideid:targeteditorID, guideitemtext : textareacontents });
alert( JSON.stringify(dynamictextareas) );

See anything wrong with this JSON2 javascript code?

For some reason this come is making a mess of things. I want to push:

<p>DDDDDD</p>

But instead it's pushing:

[{"guideid":"1","guideitemtext":"<p>\u000a\u0009u000au0009DDDDDD</p>\u000a"}]

Any ideas? Is there a better way I can build this JSON object?

+1  A: 

\u000a is identical to \n (newline) and \u0009 is identical to \t (tab).

The JSON spec states that newlines and tabs must be escaped, and thats what has happened here.

If you do not want these characters serialized, then you can remove them prior to serializing e.g with a regexp.

Sean Kinsey