0
import requests
url = "http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"
request = requests.get(url)
fetch_data = request.json()
print (request.content)
for item in fetch_data:
print(item)
JSONリクエストgeonames -> lng
内のアイテムを取得しようとしています。私はitem['lng']
データの解析JSONとPython
を利用する場合は、JSONリクエスト
{
"geonames":[
{
"lng":-99.12766456604,
"geonameId":3530597,
"countrycode":"MX",
"name":"Mexiko-Stadt",
"fclName":"city, village,...",
"toponymName":"Mexico City",
"fcodeName":"capital of a political entity",
"wikipedia":"en.wikipedia.org/wiki/Mexico_City",
"lat":19.428472427036,
"fcl":"P",
"population":12294193,
"fcode":"PPLC"
}
]
}
あなたは*辞書* 'fetch_data'を反復処理しているので、エラーメッセージがわかりますよう' item'は、文字列であるキー(例えば ' 'geonames'')、です。 – jonrsharpe
fetch_data.enumerate()の 'for key、item:' – Barmar
@Barmar ''dict'オブジェクトに 'enumerate'という属性がありません...? –