Reputation:
I have a URL which when run in the browser, displays JSON data, since I am new to coldfusion, I am wondering, what would be a good way to grab the data from the web browser? Later on I will be storing the individial JSON data into MySQL database, but I need to figure out step 1 which is grabbing the data.
Please advise.
Thanks
Upvotes: 0
Views: 971
Reputation: 595
Here is quick example:
<!--- Set the URL address. --->
<cfset urlAddress="http://ip.jsontest.com/">
<!--- Generate http request from cf --->
<cfhttp url="#urlAddress#" method="GET" resolveurl="Yes" throwOnError="Yes"/>
<!--- handle the response from the server --->
<cfoutput>
This is just a string:<br />
#CFHTTP.FileContent#<br />
</cfoutput>
<cfset cfData=DeserializeJSON(CFHTTP.FileContent)>
This is object:<br />
<cfdump var="#cfData#">
Now you can do something like this:<br />
<cfoutput>#cfData.ip#</cfoutput>
Execute this source here http://cflive.net/
Upvotes: 3
Reputation: 236
See the example Adobe gives in the deserializeJSON documentation.
Upvotes: 5