Coldfusion反序列化来自cfhttp的json,它是查询驱动的

时间:2016-02-05 06:40:05

标签: mysql json coldfusion

我正在尝试遍历搜索API以获取某些数据。我用cfoutput包装cfhttp以放置一个查询字段来代替url变量。 cfhttp和cfoutput正在运行。我的查询限制为5,我在代码中得到了我期望的五个。我遇到麻烦的部分是反序列化和倾销。 cfdump只是转储最后的结果。

这是我的代码:

<cfquery name="gameName" datasource="UNOBerry">
Select replace(g.GameTitle, ' ', '+') as GameTitle
From Games g
where left(g.gametitle,1) = 'h'
limit 5
</cfquery>

<cfoutput query="gameName">
    <cfhttp url="https://ahmedakhan-game-review-information-v1.p.mashape.com/api/v1/information?game_name=#gameName.GameTitle#" method="get" resolveurl="Yes" throwOnError="Yes">
        <cfhttpparam type="header" name="X-Mashape-Key" value="api-key" >
        <cfhttpparam type="header" name="Accept" value="application/json" >
    </cfhttp>

    #CFHTTP.FileContent#<br />
</cfoutput>

<cfset cfData=DeserializeJSON(CFHTTP.FileContent)> 

<cfdump var="#cfData#">

<cfoutput>#cfData#</cfoutput>

Json示例:

{"result":{"websites":["metacritic","ign"],"genre":["Action","Third-Person Shooter"],"developer":["SOF Studios"],"availablePlatform":[],"publisher":["SOF Studios"],"averageScore":null,"gamespot":{"userScore":0,"criticScore":0,"url":"could not find game on gamespot"},"gamesradar":{"criticScore":0,"url":"could not find game on gamesradar"},"metacritic":{"criticScore":"","userScore":"91","url":"http://www.metacritic.com/game/pc/h-hour-worlds-elite"},"name":"H-Hour: World's Elite","platform":"PC","thumbnail":"http://static.metacritic.com/images/products/games/6/bfa7f045464f857c09b058ef3bc798b8-98.jpg","rating":"","rlsdate":"TBA - Early Access","ign":{"criticScore":"-.-","userScore":"10","url":"http://www.ign.com/games/h-hour/pc-20000494"}}}

实际上,我的最终目标是将其转换为可导入我的数据库的可用json文件。因此,如果我以完全错误的方式解决这个问题,请随意将我放在我的位置。

感谢您的帮助。

0 个答案:

没有答案