JSON response need a little help
Hi I am trying to create a JSON response it needs to be like the one below. I have created a CFC that returns a validate JSON response but not in the format needed I think I am not understanding something can anyone help? Thanks Response needs to look like this {hotspots: [ {distance: 100, attribution: This is a test layer POI provider, title: My layer - snowy4, lon: 4884339, imageURL: null, line4: RADIOLIST-None,CustSlider-None, line3: SEARCHBOX - asdfdgxdg, line2: DevlId - 896Settings: range=1000, actions: [], lat: 52374544, type: 0, id: test_1}, {distance: 100, attribution: This is a test layer POI provider, title: My layer - snowy4, lon: 4887339, imageURL: null, line4: RADIOLIST-None,CustSlider-None, line3: SEARCHBOX - asdfdgxdg, line2: DevlId - 896Settings: range=1000, actions: [], lat: 52374544, type: 0, id: test_2} ], layer: snowy4, errorString: ok, morePages: false, errorCode: 0, nextPageKey: null } My CFC cfscript var response = {} response.hotspots = { distance ='100', attribution=This is a test layer POI provider, title= My layer - snowy4, lon= 53.472696, imageURL='null', line4= 'RADIOLIST-None,CustSlider-None', line3= 'SEARCHBOX - asdfdgxdg', line2= 'DevlId - 896Settings: range=1000', actions='', lat= '-2.261843', type='0', id='test_1' }; response.layer = testme; response.errorString='ok'; response.morePages='false'; response.errorCode= '0'; response.nextPageKey='null'; /cfscript which gives me the JSON... { HOTSPOTS: { TYPE: 0.0, ATTRIBUTION: This is a test layer POI provider, LINE2: DevlId - 896Settings: range=1000, TITLE: My layer - snowy4, LINE4: RADIOLIST-None,CustSlider-None, LAT: 5.2374544E7, ACTIONS: , IMAGEURL: null, LINE3: SEARCHBOX - asdfdgxdg, LON: 4884339.0, ID: test_1, DISTANCE: 100.0 }, ERRORSTRING: ok, NEXTPAGEKEY: null, LAYER: testme, MOREPAGES: false, ERRORCODE: 0.0 } ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334957 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: JSON response need a little help
To get the case to match, use the bracket structure syntax: i.e. response['hotspots'] = . will preserve the case of the key. When you do response.hotspots, CF automatically uppercases the key. On Wed, Jun 30, 2010 at 10:49 AM, Glyn Jackson glyn.jack...@newebia.co.ukwrote: Hi I am trying to create a JSON response it needs to be like the one below. I have created a CFC that returns a validate JSON response but not in the format needed I think I am not understanding something can anyone help? Thanks Response needs to look like this {hotspots: [ {distance: 100, attribution: This is a test layer POI provider, title: My layer - snowy4, lon: 4884339, imageURL: null, line4: RADIOLIST-None,CustSlider-None, line3: SEARCHBOX - asdfdgxdg, line2: DevlId - 896Settings: range=1000, actions: [], lat: 52374544, type: 0, id: test_1}, {distance: 100, attribution: This is a test layer POI provider, title: My layer - snowy4, lon: 4887339, imageURL: null, line4: RADIOLIST-None,CustSlider-None, line3: SEARCHBOX - asdfdgxdg, line2: DevlId - 896Settings: range=1000, actions: [], lat: 52374544, type: 0, id: test_2} ], layer: snowy4, errorString: ok, morePages: false, errorCode: 0, nextPageKey: null } My CFC cfscript var response = {} response.hotspots = { distance ='100', attribution=This is a test layer POI provider, title= My layer - snowy4, lon= 53.472696, imageURL='null', line4= 'RADIOLIST-None,CustSlider-None', line3= 'SEARCHBOX - asdfdgxdg', line2= 'DevlId - 896Settings: range=1000', actions='', lat= '-2.261843', type='0', id='test_1' }; response.layer = testme; response.errorString='ok'; response.morePages='false'; response.errorCode= '0'; response.nextPageKey='null'; /cfscript which gives me the JSON... { HOTSPOTS: { TYPE: 0.0, ATTRIBUTION: This is a test layer POI provider, LINE2: DevlId - 896Settings: range=1000, TITLE: My layer - snowy4, LINE4: RADIOLIST-None,CustSlider-None, LAT: 5.2374544E7, ACTIONS: , IMAGEURL: null, LINE3: SEARCHBOX - asdfdgxdg, LON: 4884339.0, ID: test_1, DISTANCE: 100.0 }, ERRORSTRING: ok, NEXTPAGEKEY: null, LAYER: testme, MOREPAGES: false, ERRORCODE: 0.0 } ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334958 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: JSON response need a little help
simply things! thanks that is something I missed yes. one last thing looking at what they want back it seems that 'hotspots' needs to be an array can you do implicit Arrays in CF like this would this not give me an error? ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334959 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: JSON response need a little help
You can do implicit array and structure creation in ColdFusion since v8. cfset myArr = [] cfset myStruct = {} Only on CF 9 however can you do this cfset myArr = [] cfset ArrayAppend( myArr, {} ) -Original Message- From: Glyn Jackson [mailto:glyn.jack...@newebia.co.uk] Sent: Wednesday, June 30, 2010 10:18 AM To: cf-talk Subject: Re: JSON response need a little help simply things! thanks that is something I missed yes. one last thing looking at what they want back it seems that 'hotspots' needs to be an array can you do implicit Arrays in CF like this would this not give me an error? ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334960 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: JSON response need a little help
cool so something like this would work?... response['hotspots'] = [{ distance ='100', attribution=This is a test layer POI provider, title= My layer - snowy4, lon= 53.472696, lat= '-2.261843', imageURL='null', line4= 'RADIOLIST-None,CustSlider-None', line3= 'SEARCHBOX - asdfdgxdg', line2= 'DevlId - 896Settings: range=1000', actions='', type='0', id='test_1' }]; ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334961 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: JSON response need a little help
Well, remember that JSON is a string representation of a complex object, not the object itself. So if you plan on passing the variable below through SerializeJSON, or ColdFusion's built in JSON returnformat then you'd be okay. andy -Original Message- From: Glyn Jackson [mailto:glyn.jack...@newebia.co.uk] Sent: Wednesday, June 30, 2010 10:39 AM To: cf-talk Subject: Re: JSON response need a little help cool so something like this would work?... response['hotspots'] = [{ distance ='100', attribution=This is a test layer POI provider, title= My layer - snowy4, lon= 53.472696, lat= '-2.261843', imageURL='null', line4= 'RADIOLIST-None,CustSlider-None', line3= 'SEARCHBOX - asdfdgxdg', line2= 'DevlId - 896Settings: range=1000', actions='', type='0', id='test_1' }]; ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334980 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm