Created
October 10, 2012 17:11
-
-
Save Flave/3866989 to your computer and use it in GitHub Desktop.
toSource() function adds crazy parentheses around each object - why?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var testObj = { | |
"foo":[ | |
{ | |
"a" : 1, | |
"b" : 2, | |
"c" : [1, 2, 3, 4] | |
}, | |
{ | |
"a" : 1, | |
"b" : 2, | |
"c" : [1, 2, 3, 4] | |
} | |
] | |
} | |
var toSourced = testObj.toSource(); | |
var stringObj = toSourced.replace(/\((.*)\)/, "$1"); | |
alert(stringObj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ich denke es gibt 2 Möglichkeiten.
Das kannst du dann mit eval() laden.
Guck mal hier
2. Du benutzt JSON.stringify(myObject, replacer); Dafür musst du aber eine externe JS Library laden. Beschrieben wird das hier und die lib gibt es hier