dangww

python机器可读数据-json

导入JSON数据相对简单。下面为打开、加载、导入、输出的操作。

import json

data = open('data.json').read()
data = json.loads(data)
for row in data:
    print(row)
        

得到字典形式的数据:

{'High': '', 'Year': 2000, 'Display Value': 43, 'Comments': '', 'Numeric': 43.0, 'WHO region': 'Africa', 'Indicator': 'Healthy life expectancy (HALE) at birth (years)', 'Country': 'Equatorial Guinea', 'World Bank income group': 'High-income', 'PUBLISH STATES': 'Published', 'Sex': 'Male', 'Low': ''}
{'High': '', 'Year': 2012, 'Display Value': 47, 'Comments': '', 'Numeric': 47.0, 'WHO region': 'Africa', 'Indicator': 'Healthy life expectancy (HALE) at birth (years)', 'Country': 'Equatorial Guinea', 'World Bank income group': 'High-income', 'PUBLISH STATES': 'Published', 'Sex': 'Both sexes', 'Low': ''}
{'High': '', 'Year': 2012, 'Display Value': 60, 'Comments': '', 'Numeric': 60.0, 'WHO region': 'Americas', 'Indicator': 'Healthy life expectancy (HALE) at birth (years)', 'Country': 'Grenada', 'World Bank income group': 'Upper-middle-income', 'PUBLISH STATES': 'Published', 'Sex': 'Male', 'Low': ''}
{'High': '', 'Year': 2012, 'Display Value': 66, 'Comments': '', 'Numeric': 66.0, 'WHO region': 'Americas', 'Indicator': 'Healthy life expectancy (HALE) at birth (years)', 'Country': 'Grenada', 'World Bank income group': 'Upper-middle-income', 'PUBLISH STATES': 'Published', 'Sex': 'Female', 'Low': ''}
{'High': '', 'Year': 2012, 'Display Value': 63, 'Comments': '', 'Numeric': 63.0, 'WHO region': 'Americas', 'Indicator': 'Healthy life expectancy (HALE) at birth (years)', 'Country': 'Grenada', 'World Bank income group': 'Upper-middle-income', 'PUBLISH STATES': 'Published', 'Sex': 'Both sexes', 'Low': ''}

 

posted on 2017-11-16 16:00  dangww  阅读(186)  评论(0编辑  收藏  举报

导航