Return to Snippet

Revision: 2239
at January 21, 2007 20:26 by markireland


Initial Code
<cfscript> 
function nowhitespace(queryname,uniqueIdColumnName,columnlist,recordcount) {
	var p="";
	var currentrow = 1;
	p = p & '"RECORDCOUNT":' & recordcount & ',' & '"UNIQUEIDS":[';
	for (ids = 1; ids lte recordcount; ids = ids+1){
		p = p & '"js' & evaluate("queryname." & uniqueIdColumnName & '[' & ids & ']') & '"';
		if (ids lt recordcount) {p = p & ',';}
		else {p = p & '],';}
		}
	p = p & '"COLUMNNAMES":[' & listQualify(columnlist,'"') & '],';
 	for (idx = 1; idx lte recordcount; idx = idx+1) 
 	{
	 p = p & '"js' & evaluate("queryname." & uniqueIdColumnName & '[' & idx & ']') & '"' & ':{';
	 p = p & '"CURRENTROW":' & currentrow & ',';
  	  for (idx1 = 1; idx1 lte listlen(columnlist); idx1 = idx1+1){
  	  	clmnname = listgetat(columnlist,idx1);
		p = p & '"' & clmnname & '":';
 	  	evalp = evaluate("queryname." & clmnname & '[' & idx & ']');
 	  	if (NOT isNumeric(evalp)) {evalp = '"' & JSStringFormat(evalp) & '"';}
 	  	if (idx1 IS listlen(columnlist)){p = p & evalp;}
 	  	else {p = p & evalp & ',';}
  	  	} 
  	  if (idx NEQ recordcount) {
  	  	  p = p & '},'; 
  	  	  currentrow = currentrow + 1;
  	  	  }
 	} idx1 = 1;
 	p =  p & '}';
 return '{' & p & '}';
}
</cfscript>

Initial URL

                                

Initial Description
in javascript use, for example: myJsonObject[&quot;js007&quot;].firstname + ' ' + myJsonObject[&quot;js007&quot;].lastnamename
to return James Bond

Initial Title
query to json oblect - that can be referenced by a unique id

Initial Tags
query, json

Initial Language
JavaScript