True. But in the case of importing json strings into JS it is necessary. In
fact eval could have been designed for json, if it weren't created well
before :).

If the myjson is just a JSON string you've outputed into a script tag, then
that would work - the JSON will be evaluated with the reset of the JS script
in the page. But if you've AJAX'd it in, or if the JSON string is actually
stored in a string, then you need to eval it:
myjson=eval("("+myjsonstring+")");

Don't ask me why the brackets are necessary, I could never be bothered
finding out.

Your error could be the result of anything, but a couple of things to check:
- Check the json string in the browser to make sure it is valid. Is it well
formed (a problem here would probably cause a JS error)? Does it have the
variables you expect (you would need to look at the creation of the JSON to
fix this)? If you're loading the JSON via AJAX, is it being loading
correctly (CF errors are not valid JSON :) )?

Blair

On 12/6/06, Mark Ireland <[EMAIL PROTECTED]> wrote:
>
>  A simple test like this does work:
>
> a href="##" onclick="alert(myjson.DATA.MYVARIABLE[0] + myjson.RECORDCOUNT)">Hi
> There</a
>
> I am told in js eval() is evil and its (ab)use is a cry for help. Just
> like evaluate() in cf.
>
> ------------------------------
> From:  *"Mark Mandel" <[EMAIL PROTECTED]>*
> Reply-To:  [EMAIL PROTECTED]
> To:  [EMAIL PROTECTED]
> Subject:  *[cfaussie] Re: json in js code*
> Date:  *Thu, 7 Dec 2006 15:19:19 +1100*
> >
> >I'm not totally up to speed on json, but doesn't it have to be eval() 'd
> ?
> >
> >Mark
> >
> >On 12/7/06, Mark Ireland <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > >
> > > Can I use stuff from a json string like this?
> > >
> > >
> > > var s = 'something';
> > >
> > > for (var j in myjson.RECORDCOUNT) {
> > >
> > > var id = myjson.DATA.MYVARIABLE[j];
> > >
> > > chk = document.getElementById(s + id);
> > >
> > > // chk = document.getElementById(s + id.toString());
> > >
> > > }
> > >
> > > It dont work!
> > > ________________________________
> > > Advertisement: Amazing holiday rentals?
> > >  >
> > >
> >
> >
> >--
> >E: [EMAIL PROTECTED]
> >W: www.compoundtheory.com
> >
> >millions of Australians using Live Search. Try 
> >live.com.au<http://g.msn.com/8HMAENAU/2731??PS=47575>
> >
>


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to