下面的代碼我有像一個款待作品。它從我的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