• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Documentation on making API calls, parsing, and formatting.

Enthusiast ,
Jan 25, 2016 Jan 25, 2016

Copy link to clipboard

Copied

Will someone provide me information/links to making API calls, parsing, and/or formatting the JSON result in ColdFusion. If there are video tutorials, that'll be awesome.

Views

754

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 26, 2016 Jan 26, 2016

It's not working. This is what is working..got it from StackOverflow. I assumed the deserializeJSON automatically turned into query but it was not. Looks like it's a struct.

<cfif structKeyExists(cfData, 'weather') AND isArray(cfData.weather)>

        <cfoutput>

        Name: #cfData.name#

         <cfloop index="i" from="1" to="#arrayLen(cfData.weather)#">       

            <h4>Weather: #cfData.weather.main#</h4>

            <h4>Description: #cfData.weather.description#</h4>

        </cfloop>

       

...

Votes

Translate

Translate
Advocate ,
Jan 25, 2016 Jan 25, 2016

Copy link to clipboard

Copied

There are examples in the documentation. See the serializeJSON and deserializeJSON functions.

Cheers

Eddie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 25, 2016 Jan 25, 2016

Copy link to clipboard

Copied

Okay, so I was following the example for the deserializedJSON function and it's giving me the "Element COLUMNS is undefined in CFDATA." error.

<cfhttp url="https://app.knowledgeowl.com/api/head/category.json" method="get" >

<!--- JSON data is sometimes distributed as a JavaScript function.

The following REReplace functions strip the function wrapper. --->

<cfset theData=REReplace(cfhttp.FileContent,

"^\s*[[:word:]]*\s*\(\s*","")>

<cfset theData=REReplace(theData, "\s*\)\s*$", "")>

<!--- Test to make sure you have JSON data. --->

<cfif !IsJSON(theData)>

  <h3>The URL you requested does not provide valid JSON</h3>

  <cfdump var="#theData#" >

  <!--- If the data is in JSON format, deserialize it. --->

<cfelse>

  <cfset cfData=DeserializeJSON(theData)>

  <!--- Parse the resulting array or structure and display the data.

  In this case, the data represents a ColdFusion query that has been

  serialized by the SerializeJSON function into a JSON structure with

  two arrays: an array column names, and an array of arrays,

  where the outer array rows correspond to the query rows, and the

  inner array entries correspond to the column fields in the row. --->

  <!--- First, find the positions of the columns in the data array. --->

  <cfset colList=ArrayToList(cfData.COLUMNS)>

  <cfset idIdx=ListFind(colList, "id")>

  <cfset statusIdx=ListFind(colList, "status")>

  <!--- Now iterate through the DATA array and display the data. --->

  <cfoutput>

  <cfloop index="i" from="1" to="#Arraylen(cfData.DATA)#">

  <h3>Category: #cfData.DATA[cateIdx]#</h3>

  <h3>Name: #cfData.DATA[1][nameIdx]#</h3>

  </cfloop>

  </cfoutput>

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 25, 2016 Jan 25, 2016

Copy link to clipboard

Copied

So, does anyone know why I am getting the Element COLUMNS is undefined in CFDATA error? I'm following this tutorial, ColdFusion Help | DeserializeJSON.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 26, 2016 Jan 26, 2016

Copy link to clipboard

Copied

Okay, so I tried this the following API from OpenWeatherMap and it gave the Error in custom script module error.

<cfhttp url="http://api.openweathermap.org/data/2.5/weather?zip=55101,us&appid=44db6a862fba0b067b1930da0d769e98" method="get" >

Any idea?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 26, 2016 Jan 26, 2016

Copy link to clipboard

Copied

Okay, I'm getting this Element COLUMNS is undefined in CFDATA. error again. Why am I kept getting the COLUMNS error?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 26, 2016 Jan 26, 2016

Copy link to clipboard

Copied

Okay, my problem is the the cfData. I tried to output the length and it gave me this Error in custom script module error.

<cfoutput>

Length: #cfData.length#

</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2016 Jan 26, 2016

Copy link to clipboard

Copied

@2Charlie

In the example from deserializeJSON , change each of the 3 occurrences of ListFind to listFindNoCase. I have reported this error to Adobe.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 26, 2016 Jan 26, 2016

Copy link to clipboard

Copied

LATEST

It's not working. This is what is working..got it from StackOverflow. I assumed the deserializeJSON automatically turned into query but it was not. Looks like it's a struct.

<cfif structKeyExists(cfData, 'weather') AND isArray(cfData.weather)>

        <cfoutput>

        Name: #cfData.name#

         <cfloop index="i" from="1" to="#arrayLen(cfData.weather)#">       

            <h4>Weather: #cfData.weather.main#</h4>

            <h4>Description: #cfData.weather.description#</h4>

        </cfloop>

        </cfoutput>

    </cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation