Code Samples

Page Contents

PHP

<?php $json_string = file_get_contents("http://api.wunderground.com/api/Your_Key/geolookup/conditions/q/IA/Cedar_Rapids.json"); $parsed_json = json_decode($json_string); $location = $parsed_json->{'location'}->{'city'}; $temp_f = $parsed_json->{'current_observation'}->{'temp_f'}; echo "Current temperature in ${location} is: ${temp_f}\n"; ?>

Ruby

require 'open-uri' require 'json' open('http://api.wunderground.com/api/Your_Key/geolookup/conditions/q/IA/Cedar_Rapids.json') do |f| json_string = f.read parsed_json = JSON.parse(json_string) location = parsed_json['location']['city'] temp_f = parsed_json['current_observation']['temp_f'] print "Current temperature in #{location} is: #{temp_f}\n" end

Python

import urllib2 import json f = urllib2.urlopen('http://api.wunderground.com/api/Your_Key/geolookup/conditions/q/IA/Cedar_Rapids.json') json_string = f.read() parsed_json = json.loads(json_string) location = parsed_json['location']['city'] temp_f = parsed_json['current_observation']['temp_f'] print "Current temperature in %s is: %s" % (location, temp_f) f.close()

ColdFusion

<cfhttp url="http://api.wunderground.com/api/Your_Key/geolookup/conditions/q/IA/Cedar_Rapids.json"> <cfset parsed_json = deserializeJSON(cfhttp.fileContent)> <cfset location = parsed_json.location.city> <cfset temp_f = parsed_json.current_observation.temp_f> <cfoutput>Current temperature in #location# is #temp_f#</cfoutput>

JavaScript with jQuery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script> jQuery(document).ready(function($) { $.ajax({ url : "http://api.wunderground.com/api/Your_Key/geolookup/conditions/q/IA/Cedar_Rapids.json", dataType : "jsonp", success : function(parsed_json) { var location = parsed_json['location']['city']; var temp_f = parsed_json['current_observation']['temp_f']; alert("Current temperature in " + location + " is: " + temp_f); } }); }); </script>