Solved

Reading cfhttp json call and outputing to coldfusion friendly source.

Posted on 2012-12-21
2
953 Views
Last Modified: 2013-01-08
Hello,

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.

Thx!

<cffunction name="ipLocation"
            access="remote"
            returntype="struct"
            displayname="ipLocation"
            output="no">

    <cfset var local = StructNew()>

    <cfset local.url = "http://www.geoplugin.net/extras/nearby.gp?limit=10&radius=50&format=json">

    <cfhttp result="local.ipRequest"
            url="#local.url#"
            method="get"
            timeout="5"
            throwOnError="yes"/>
 
</cffunction>

Open in new window

0
Comment
Question by:brihol44
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
Comment Utility
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
<cfelse>
	<!--- deserialize it into an array of structures --->
    <cfset jsonData = DeserializeJSON(theData)>
    <cfif isArray(jsonData)>
		<cfoutput>
		<!--- loop through it and display the "place" and "region" values --->
	    <cfloop array="#jsonData#" index="elem">
    		place/region: #elem.geoplugin_place# #elem.geoplugin_region# <br>
	    </cfloop>
	    </cfoutput>
	</cfif>
</cfif> 

Open in new window

0
 

Author Closing Comment

by:brihol44
Comment Utility
Cool! Thx!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
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 video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

16 Experts available now in Live!

Get 1:1 Help Now