JSON data rendering, how to get quotes not escaped?

I'm having another problem. I'm trying to get jqGrid working using
its built-in ajax call, with JSON. In my handler, I return the data
with:

event.renderData(type="JSON",data=data.result,contentType='application/
json');

jqGrid's screwy requirements want the data as a comma-delimited list,
rather than a key/value pair. And in the examples on the jqGrid site,
they show the values as being quoted (think QuotedValueList). But
when I format the data, it comes through as escaped (backslashes
before each quote). Without quotes, the entire list gets quoted. And
what I'm seeing now, and I suspect it maybe related, is the data
itself is showing up one character per column. For example:

4 | 4 | 0 | , | B | a | r | b | NaNaNaN (etc)

The vertical bars represent the individual columns in the grid.

Is there a way to get ColdBox to NOT escape the quotes?

Rob

This is more of the ColdFusion JSON parser doing it. I think you might do things manually for this. I am not sure as I am not familiar with jqGrid. ANybody?

I use jqGrid all the time without any issues.

My response includes escaped quotes

Example response

{"ROWS":[["1","<a href=\"someURL\" >Manage<\/a>","<a href=\"someURL\" >Edit<\/a>","some data"]],"PAGE":"1","RECORDS":"5","TOTAL":"1.0"}

Rows needs to be an array of data, and the gridData needs to be a struct.

rc.gridData = {total=totalPages,page=currentpage,records=totalCount,rows=arrayofRows};

event.renderData(type="json",data=rc.gridData);

Hope that helps.

Curt Gratz
Computer Know How

Yeah that's exactly how I'm doing it. Here's my code... very similar:

  <cffunction name="StructToValueList" access="public" output="false"
returntype="string">
    <cfargument name="obj" type="struct" required="yes">
    <cfargument name="keys" type="string" required="no"
default="#StructKeyList(arguments.obj)#">

    <!--- This function takes a structure and basically rips the keys
out of it, making it a list. --->

    <cfscript>
    var count = "";
    var myArr = ArrayNew(1);
    </cfscript>

    <cfloop index="count" list="#arguments.keys#">
       <cfif Len(arguments.obj[count]) gt 0>
        <cfset ArrayAppend(myArr, '#arguments.obj[count]#')>
      <cfelse>
        <cfset ArrayAppend(myArr, 'XXX')>
      </cfif>
    </cfloop>

    <cfreturn ArrayToList(myArr)>

  </cffunction>

<cfloop index="temp.count" from="#temp.startrow#" to="#temp.endrow#">
  <cfscript>
  x = x + 1;
  temp.cellArr[x] = StructNew();
  temp.cellArr[x].id = temp2.result[temp.count].contact_id;
  temp.cellArr[x].cell =
StructToValueList(obj=temp2.result[temp.count],keys="contact_id,company,first_name,last_name,title,state,industry,shrm,first_submit");
  </cfscript>
</cfloop>

ret = {total=temp.totalPages, page=temp.page,
records=temp2.survey.recordcount, rows=temp.cellArr};

{"rows":[{"cell":"440,XXX,Barbara,Smith,XXX,XXX,XXX,XXX,XXX","id":440},
{"cell":"486,XXX,Beth,Jones,XXX,XXX,XXX,XXX,XXX","id":486},
{"cell":"488,XXX,Betsy,Johnson,XXX,XXX,XXX,XXX,XXX","id":488},
{"cell":"380,XXX,Bruce,Jenner,XXX,XXX,XXX,XXX,XXX","id":380},
{"cell":"370,XXX,Candy,Cane,XXX,XXX,XXX,XXX,XXX","id":370},
{"cell":"425,XXX,Carolyn,Hooper,XXX,XXX,XXX,XXX,XXX","id":425},
{"cell":"379,XXX,Miguel,Ramirez,XXX,XXX,XXX,XXX,XXX","id":379},
{"cell":"496,XXX,l,c,XXX,mi,XXX,XXX,XXX","id":496},
{"cell":"406,XXX,Jim,Cooper,XXX,XXX,XXX,XXX,XXX","id":406}],"page":
1,"records":200,"total":10}

(note: I edited out some records to save space, and changed the names
to protect the innocent). This example has "XXX" substituted for
empty values, just as a test. But note that the quotes aren't around
each value, it's around the whole string.

What am I doing wrong?? This is maddening. :slight_smile:

Rob

You are returning an array of structs,

You need an array of arrays

Data like this
ar = arraynew(1);

ar[1] = [ 'col1 data row 1','col2 data row 1','col3 data row 1' ];
ar[2] = [ 'col1 data row 2','col2 data row 2','col3 data row 2' ];

returns this, which jqGrid can handle...
{"ROWS":[["col1 data row 1","col2 data row 1","col3 data row 1"],["col1 data row 2","col2 data row 2","col3 data row 2"]],PAGE":"1","RECORDS":"5","TOTAL":"1.0"};

AHA! That was it. Thanks! I got it working.

Rob