That code looks like it will run without erroring, but know that your
struct keys will be uppercase once they reach Flash unless you use the
array notation I showed you.
Other than the fact that the pound signs are unnecessary, I don't see
any reason why that wouldn't work.

If this is a web service, just place the code in a cffunction of a
cfcomponent and hit it directly.  In fact, you don't even need the
serializeJSON function.  You can simply <cfreturn obj>  at the end of
your method and add the returnFormat=JSON parameter to the URL like
Cutter recommended.

file name: myWebservice.cfc

<cfcompnent name="myWebservice">
<cffunction name="myMethod" output="false">
.. Your code here ...
<cfreturn obj>
</cfcfunction
</cfcomponent>

Then the URL to call which will return your JSON directly would be:
http://www.yourserver.com/myWebservice.cfc?method=myMethod%returnFormat=json

ColdFusion makes this so ridiculously simple it's scary.

~Brad

-------- Original Message --------
Subject: Re: JSON help
From: Stefan Richter <[email protected]>
Date: Fri, October 09, 2009 11:18 am
To: cf-talk <[email protected]>


I've now done the following - anything wrong with that?
 
 <cfset obj = StructNew()>
 <cfset obj.total = list.recordcount>
 <cfset obj.items = ArrayNew(1)>
 <cfloop query="list">
 <cfset item = StructNew()>
 <cfset item.id = #fileid#>
 <cfset item.title = #entered_name#>
 <cfset ArrayAppend(obj.items,item)>
 </cfloop>
 
 <cfset jsondata = serializeJSON(obj)>
 <cfoutput>#jsondata#</cfoutput>




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:327072
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to