Tuesday, May 5, 2009

JSON -- headache eliminator, part 1

I haven't used JSON very much. I like it, but I just haven't had a chance to really get down into it too deeply. However, this is the 2nd time that I've been bitten by a stupid syntax thing. The solution is on many many blogs out there, but hopefully having typed this myself, I might finally remember it.

Server side, when you are creating your object, you might concentrate on the data, and end up sending a string like this:

{ "someproperty" : "10" }

And, client side, you want to use it like this:

var o = eval(result);

Kaboom! What the hell? Why?

Because you forgot the parentheses:

var o = eval( "(" + result + ")" );

All is right with the world again.

DO NOT FORGET THE DAMN PAREN WRAPPERS!!!!

No comments:

Post a Comment