[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Reading cfhttp json call and outputing to coldfusion friendly source.

Posted on 2012-12-21
Medium Priority
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 = "http://www.geoplugin.net/extras/nearby.gp?limit=10&radius=50&format=json">

    <cfhttp result="local.ipRequest"

Open in new window

Question by:brihol44
LVL 52

Accepted Solution

_agx_ earned 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 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