On Aug 21, 8:30 pm, Andrew Poulos <ap_p...@hotmail.comwrote:
I'm trying to use the String method parseJSON (that is created in the
javascript of a frameset) in one of the frames but I don't know how to
correctly reference it. This:
notes = str.parseJSON();
doesn't seem to work - I get the error "str.parseJSON is not a
function". And this:
notes = str.parent.parseJSON();
also gives a similar error. If I code directly into the frameset I get
the results I expect.
Now I'm not sure where the issue is. How can I use a method that's
defined in a frameset in a frame?
parseJSON is not a native function yet. If you use Douglas Crockford's
reference implementation the above code should work.
http://www.json.org/js.html
Douglas's code augments build in objects (eg String) and this is
considered a bad practice by many. Since it is a reference
implementation, his implementation is to show how JSON will work
eventually not necessarily how it should be implemented now.
Is the JSON from a trusted source? If so then you don't need to use
the parseJSON function which just checks the JSON matches a particular
regular expression. If it is a trusted source you can just do
eval('(' + str + ')');
which is what the json parser ends up doing anyway after the regexp
check.
Peter