Coldfusion jsStringFormat issue

Coldfusion jsStringFormat issue

docwisdomdocwisdom Posts: 1Questions: 0Answers: 0
edited October 2011 in General
I know there arent a whole lot of coldfusion developers out there, especially coldfusion/datatables users, but I shall give my question a shot.

I am currently using the coldfusion server side processing script from the site and for the most part everything is working great. It was until users started populating with their own data, that I ran into problems with special characters not being escaped when passed into the json string from the query. I know that the jsStringFormat() function is supposed to escape all characters output from each column and row, but I am still getting double quotes and ampersands in my json, which obviously breaks datatables.

Heres is a sample of the json coming through. Notice the ampersand in the first line. It is however escaping the apostrophe in the last line correctly.

[code]

{"sEcho": 1,
"iTotalRecords": 659,
"iTotalDisplayRecords": 13,
"aaData": [

["52","138d 4h 7m","01- Operational","","Replace guest WiFi system @ S&S","In Progress","Work Request",""]
,
["410","85d 4h 7m","04- Support","","NEC phone system audit","In Progress","Work Request",""]
,
["591","27d 4h 7m","04- Support","","Evaluate replacement for retrospect","In Progress","Work Request",""]
,
["628","14d 4h 7m","04- Support","","Conference Call Phone Installation","Waiting on parts","Work Request","Oct 21, 2011"]
,
["624","14d 4h 7m","04- Support",""," Phone move to Shorline Apartment Unit 2","Being Researched","Work Request","Oct 21, 2011"]
,
["68","138d 4h 7m","04- Support","","configure scanner Carl\'s desk","Approved","Work Request",""]
] }
[/code]

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    The apostrophe (single quote) shouldn't be escaped here, just any double quotes (speech marks) that are found inside the string. If you remove the escaping, then the above is valid JSON ( http://jsonlint.com ).

    Allan
  • cjazinskicjazinski Posts: 1Questions: 0Answers: 0
    What i ended up doing was something like this..

    [code]

    JSONcomment = REREPLACE(comment.getComment(), "\'", "'", 'all');
    writeOutput('"#JSStringFormat(JSONcomment)#"');

    [/code]
This discussion has been closed.