|
import json
# load data into a list
filename = 'D:\TestProject\pycentosprj\population_data.json'
with open(filename) as f:
#pop_data=[{"Year": "2010","Country Name": "CN","Value": "10"}]
pop_data = json.load(f)
# print the Y2000 population for each country
for pop_dict in pop_data:
try:
if pop_dict['Year'] == '2010':
country_name = pop_dict['Country Name']
population = pop_dict['Value']
except ValueError:
print('missing data')
else:
print(country_name + ": " + population)
以上是我在python3.6运行通过的代码,请参考。
|
|