Version 0.2
Corrected the escape function. Unlike XML, JSON does not have a CDATA capability. This makes escaping certain characters a requirement. Just like the toXML.QueryToXML() function there is an argument called 'cDataCols', which is a list of columns that are to use the CDATA element. In toJSON, this argument is used to escape those characters for the columns listed.

first of all thanks for creating this CFC, saved me the troube of looking at how to create JSON data by myself or using cfjson. i was using toxml before for my Spry results, but switched to toJSON now.
i have a problem though, it seems Spry doesn't like quotes around numbers, as described here:
http://www.adobe.com/cfusion/webforums/forum/messa...
any chance for a fix for this? ;D
thanks for your hard work
how does one return the json results from a CFC? no matter what returntype is specify, i always get the "<wddxPacket version='1.0'><header/><data><string>" etc. in front of the actual content, which breaks Spry of course =\
Thank you for trying toJSON. Actually, JavaScript in general doesn't like quote marks in data. To work around this convert the quote marks to HTML ", then add this Spry script to the page to decode the column:
<!--// decode columns -->
function DecodeHTMLColumn(notificationType, notifier, data)
{
if (notificationType != "onPostLoad" || dsPO.getRowCount() < 1)
return;
var rows = ds.getData();
var numRows = rows.length;
for (var i = 0; i < numRows; i++)
{
var row = rows[i];
if (row.MYCOLUMN)
row.MYCOLUMN = Spry.Utils.decodeEntities(row.MYCOLUMN);
}
}
dsPO.addObserver(DecodeHTMLColumn);
Be careful where you use this code. Because it is decoding encoded HTML and JavaScript, any field that is processed by it, could be subject to cross site script injection.
As for WDDX output; Change the returntype to a string and return the variable to a display page with this code:
<cfsetting showdebugoutput="false" />
<cfcontent type="text/html" ><cfoutput>#trim(request.json)#</cfoutput>
Or change the output type of the function to output="True" and use the above code in your function.
Hope this helps you.
Doug
i got rid of the WDDX output using your suggestion, all i had to change was set the returntype to "any" instead of "string", since string still added the "<wddx etc." at the end of the return, while any does not!
i can't get the quotes problems working though. isn't there a way to build in isNumeric() into the cfc to decide whether to add quotes to the output or not?
thanks again!
Sorry for not it explaining that better.
Please see my comments on your thread in the forum.
The code above is intended to keep quote marks and other HTML usable or displayed in the values. Not to make a string into a number. Also, to use it you need to change the MYCOLUMN to the name of your column.