I was pulling my hair out today, trying to turn a JSON string back into a Javascript Object using the "eval" function.
Turns out, you have add parenthesis to your JSON code.
Example would be:
var jsonString = Object.toJSON(jsonObject);
Where the jsonString would equal:
{ "id" : "jeffreystune", "name": "jeffreystune.blogspot.com"}
"id" would be an "invalid label" during an eval(jsonString);
The solution is simple, but hard to find:
var copyJsonObject = eval( "(" + jsonString +")" );
Ugh! Welcome to my geeky coding world.
~Jeffrey
2 comments:
從未遭遇失敗的人,對自己或是別人,都是一知半解的。 ..................................................
用心經營的blog~您的部落格文章真棒!! ........................................
Post a Comment