URL에서 날씨 정보를 얻고 있습니다.
weather = urllib2.urlopen('url')
wjson = weather.read()
그리고 내가 얻는 것은 :
{
"data": {
"current_condition": [{
"cloudcover": "0",
"humidity": "54",
"observation_time": "08:49 AM",
"precipMM": "0.0",
"pressure": "1025",
"temp_C": "10",
"temp_F": "50",
"visibility": "10",
"weatherCode": "113",
"weatherDesc": [{
"value": "Sunny"
}],
"weatherIconUrl": [{
"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png"
}],
"winddir16Point": "E",
"winddirDegree": "100",
"windspeedKmph": "22",
"windspeedMiles": "14"
}]
}
}
원하는 요소에 어떻게 액세스 할 수 있습니까?
내가 할 경우 : 다음과 같은 print wjson['data']['current_condition']['temp_C']오류가 발생합니다.
문자열 인덱스는 str이 아닌 정수 여야합니다.
requestsJSON과 잘 어울리는 놀라운 방법입니다. 복잡한 URL을 다루고 있다면 .. 사용하세요.