× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How do i pull out certain data from this json response?

Jim Kelly
Jul 13, 2015
<p>Your result object returned from json.loads will be a dictionary, so you can print the value like so:</p> <pre><code>print result['region_name'] </code></pre> <p>Or even better, a bit more defensively, in the event that key doesn't exist:</p> <pre><code>print result.get('region_name', 'No region specified') </code></pre> <p>Also note that your urllib call should be:</p> <pre><code>response = urllib.urlopen('http://freegeoip.net/json/').read() </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/28440953/How%20do%20i%20pull%20out%20certain%20data%20from%20this%20json%20response?/28441053">Stack Overflow</a>.</p>
comments powered by Disqus