I ended up changing the JSONEncode function from CFLIB to create this form:
"errors":{}
still, js doesn't really like this much either, but it will still
parse it. I won't give you a length property as in
alert(rtn.errors.length); so I ended up just sending a total error
count property also.
On 12/5/05, Jim Davis <[EMAIL PROTECTED]> wrote:
> > -----Original Message-----
> > From: Marlon Moyer [mailto:[EMAIL PROTECTED]
> > Sent: Monday, December 05, 2005 7:27 PM
> > To: CF-Talk
> > Subject: OT: JSON
> >
> > I'm trying to return a structure of errors to my Ajax call. If there
> > are no errors, it will return an empty structure called errors. The
> > eval'ing this string "{"errors":{null}}" causes javascript to barf.
> > Is this the right format for JSON to represent an empty structure?
>
> I wouldn't think so.
>
> Remember that JSON doesn't actually define anything really: all JSON is
> normal, everyday, plain-jane JavaScript literal notation. Nothing more,
> nothing less.
>
> The braces represent an object and that's your problem. What your string is
> saying is that you have an object and that object has a property called
> "errors" which is also an object and THAT object has a property called
> "null" which is illegal.
>
> You can't define the "outer" name of an object in JSON (or really in
> anything) since it has to be assigned to a variable in the caller but to get
> close to what you want you would need something like this (this is from
> memory so don't take it at face value):
>
> {"errors":null}
>
> or
>
> {"errors":{}}
>
> I think the latter is closest to what you're looking for.
>
> Jim Davis
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:226190
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54