Reading cfhttp json call and outputing to coldfusion friendly source.

Posted on 2012-12-21
Last Modified: 2013-01-08

I'm getting the feed info but I'm trying to figure out how to read the feed and convert it into Coldfusion friendly use. Basically I'm wanting to output the city and state into a 2d array.


<cffunction name="ipLocation"

    <cfset var local = StructNew()>

    <cfset local.url = "">

    <cfhttp result="local.ipRequest"

Open in new window

Question by:brihol44
LVL 52

Accepted Solution

_agx_ earned 250 total points
ID: 38715795
Using the regex from your other question the deserialized result looks like an array of structures. So you could just return the array as is, then loop through it elsewhere:

<!--- Note: Always check the CFHTTP response code for errors first. ---> 
<cfset theData = REReplace(local.ipRequest, "^\s*[[:word:]]*\s*\(\s*","")>
<cfset theData = REReplace(theData, "\s*\)\s*$", "")>

<!--- Test to make sure you have JSON data. --->
<cfif !IsJSON(theData)>
    Error not valid JSON
	<!--- deserialize it into an array of structures --->
    <cfset jsonData = DeserializeJSON(theData)>
    <cfif isArray(jsonData)>
		<!--- loop through it and display the "place" and "region" values --->
	    <cfloop array="#jsonData#" index="elem">
    		place/region: #elem.geoplugin_place# #elem.geoplugin_region# <br>

Open in new window


Author Closing Comment

ID: 38757716
Cool! Thx!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them ( . I did keep the main js functions but made sever…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now