Skip to content

Instantly share code, notes, and snippets.

@coldfumonkeh
Created September 14, 2013 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coldfumonkeh/6565579 to your computer and use it in GitHub Desktop.
Save coldfumonkeh/6565579 to your computer and use it in GitHub Desktop.
<!--- Make the request to the API --->
<cfhttp
url="http://search.twitter.com/search.json?q=coldfusion&rpp=10"
method="get"
result="jsonTweets" />
<!--- Convert JSON to array of structs --->
<cfset jsonData = deserializeJSON(jsonTweets.fileContent) />
<!--- Check we have records returned to us --->
<cfif arrayLen(jsonData.results)>
<!--- We want to provide the query with column names --->
<cfset strColType = '' />
<!--- To do this, we'll take the first result item... --->
<cfset stuFirstTweet = jsonData.results[1] />
<!--- and get the list of keys from the structure. --->
<cfset thisKeyList = structKeyList(stuFirstTweet) />
<!---
We now need to provide the column data type.
This example assumes everything is a VarChar.
Looping over the list of keys, we'll append a
datatype to the column type list defined earlier.
--->
<cfloop list="thisKeyList" index="listItem">
<cfset listAppend(strColType,'varChar') />
</cfloop>
<!---
Generate the new query, passing in the
column list, column type list and the data.
--->
<cfset qryTweets = queryNew(
thisKeyList,
strColType,
jsonData.results
) />
</cfif>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment