下面的代码我有像一个款待作品。它从我的SQL数据库表中取出数据并将其输出到cfc中的下面的结构中,输出从我的移动应用程序中调用,并且代码按需要工作。将JSON数据转换为ColdFusion结构
<cfset currentRow=1>
<cfloop query="LT_Customers">
<cfset tempData = structNew()>
<cfset tempData["imei"] = LT_Customers.imei[currentRow]>
<cfset tempData["id"] = LT_Customers.id[currentRow]>
<cfset tempData["name"] = LT_Customers.last_name[currentRow]>
<cfset tempData["model"] = LT_Customers.Model[currentRow]>
<cfset tempData["trackee"] = LT_Customers.trackee[currentRow]>
<cfset tempData["mobile"] = LT_Customers.mobile[currentRow]>
<cfset tempData["app_user_mobile"] = LT_Customers.app_user_mobile[currentRow]>
<cfset arrayAppend(result, tempData)>
<cfset currentRow=currentRow+1>
</cfloop>
<cfreturn result>
</cffunction>
我现在有数据来自web服务,它以JSON格式返回到我的页面。我想要做的就是复制上面的内容,这样我的cfc函数就可以按照上面所示的方式输出JSON数据。 WebService的输出数据如下
<cfhttp url="http://api.sensis.com.au/v1/test/search?key=czsjp3f8xhd835vg6xfw8ber&query=vetinary%20and%20clinic&radius=1&location=-37.7833,144.9667" method="get" result="httpResp" timeout="120">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
</cfhttp>
<cfset Data=DeserializeJSON(httpResp.filecontent)>
<cfdump var="#Data#">
已经花了很多时间研究如何实现我要承认,我从那些更需要帮助上述经历他们自己。我只需要能够生成相同的结构,我已经使用JSON内容,因为我有SQL查询(是的,我欣赏列名是不同的)
我在此先感谢您的任何帮助,可以提供。
你最终的目标是什么?似乎你正在采取一种非常迂回的方式来输出查询。 –
嗨马特,最后的目标是能够从web服务输出数据,就像我从查询示例中获得的那样。我编写了一个调用cfc的iphone应用程序,并且cfc返回了初始示例中显示的结构中的数据,应用程序页面然后处理数据并将其显示在应用程序页面的列表中。我很高兴与示例查询的工作方式和它为我的应用程序生成的输出,我只需要从JSON数据输出相同的结构 – user3288814