Created
September 14, 2013 20:58
-
-
Save coldfumonkeh/6565579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- 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