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': ''}
python机器可读数据-json的更多相关文章
- python 学习(json)(转)
Json简介:Json,全名 JavaScript Object Notation,是一种轻量级的数据交换格式.Json最广泛的应用是作为AJAX中web服务器和客户端的通讯的数据格式.现在也常用于h ...
- Python序列化之json与pickle
1.json介绍 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Progra ...
- python序列化模块json和pickle
序列化相关 1. json 应用场景: json模块主要用于处理json格式的数据,可以将json格式的数据转化为python的字典,便于python处理,同时也可以将python的字典或列表等对象转 ...
- python实现的json数据以HTTP GET,POST,PUT,DELETE方式页面请求
一.JSON简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programm ...
- python知识:json格式文本;异常处理;字符串处理;unicode类型和str类型转换
python进程中的实例和json格式的字符串之间的映射关系是非常直接的,相当于同一个概念被编码成不同的表示: stream in json form ----json.loads(str)----- ...
- python中的 json 模块使用
(1)python 中生成 json 字符串: import json data = dict(ret=0, msg="Welcome, Login success!") json ...
- Python第八天——Json
json 模块 json 模块提供了非常完善的 Python 对象到 JSON 格式的转换 import json d = dict(name='Bob',age=20,score=88) json. ...
- python 对象和json互相转换
一.python对json的支持 从python2.6开始,python标准库中添加了对json的支持,操作json时,只需要import json即可. 二.python对象转换成json字符串 在 ...
- python中报错"json.decoder.JSONDecodeError: Expecting value:"的解决
在学习python语言中用json库解析网络数据时,我遇到了两个编译错误:json.decoder.JSONDecodeError: Expecting property name enclosed ...
随机推荐
- JS实现打开本地文件或文件夹 ActiveXObject
IE浏览器打开C盘,测试可用. 如果浏览器报错提示:ActiveXObject is not defined Internet 选项 -> 安全 - >安全级别,调低级别 function ...
- 部署springboot项目时 打包成jar时包中html,js,css文件缺失
问题 打包出来的jar包里面没有html,js,css文件 解决方案 在pom.xml文件下的build选项中的src/main/resources的目录下 添加配置 <build> &l ...
- 基于Ocelot的gRpcHttp网关
什么是gRpcHttp网关 通俗的讲就是将gRpc提供的服务以rest api的形式提供出去,不需要再单独的写一个webapi去做这件事. gRpcHttp网关好处 减少不必要代码,减少中间层提高通讯 ...
- heap_sort
(from wikipedia) 构建步骤: 建成一个大顶堆 第一个元素依次和最后一个元素交换,由于交换后新的堆顶元素可能违反大根堆的性质,因此需要对当前无序区(1,2,...,n-1)调整为新堆 不 ...
- React Native图片缓存解决方案
1. react-native-fetch-blob 将图片存在本地的一个东西 2. react-native-img-cache 自动缓存的一个东西 上面装好后 就可以使用啦 import {Cac ...
- Windows 循环根据进程名称 存在则删除该进程
@echo off:Looptasklist | findstr /i "javaw.exe" >nul 2>nul && (taskkill -f / ...
- c#领域驱动设计
代码是个程序员都能写, 怎么的代码才是好的, --------------------------------------------------------------------------- ...
- Asp.Net MVC 从客户端<a href="http://www....")中检测到有潜在危险的 Request.Form 值
Asp.Net MVC应用程序, Framework4.0: 则需要在webconfig文件的 <system.web> 配置节中加上 <httpRuntime requestVal ...
- HBuild 连接安卓手机
设备:一部电脑.一部安卓手机.一条数据线 1. 数据线连接电脑和安卓手机: 2. 安卓手机--> 设置 -- > 开发者选项 --> 点进去,找到USB调试并且打开,例: ...
- classList用法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...