python 2.7 - How to extract a value in a nested json source? -


I'm trying to get the temperature from a JSN source. It is nested and I can not understand how a nested value is obtained from a JSN file or URL. Even my codes have come so far:

  #! / Usr / bin / python import urllib2 import json f = urllib2.urlopen ('http://api.openweathermap.org/data/2.5/find?q=London&units=metric') json_string = f.read () parsed_json = Json.loads (json_string) temp = parsed_json ['list'] Print "The current temperature is:% s"% (temp) f.close ()   

Now I can find all Value only once but do not have a special value (temporarily in my case) I like to get value without U'temp: if possible.

u'temp ' How does Python Unicode Represents the objects that the JS string is parsed in Python. What are you looking for?

  print temp [0] ['main'] ['temp']   

I do not know the structure of the API that you are calling, therefore it Can make quite a few assumptions, but it will give you raw temperatures.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -