json.loads():解析一个有效的JSON字符串并将其转换为Python字典
json.load():从一个文件读取JSON类型的数据,然后转转换成Python字典

 

Python中json.load()和json.loads()的区别

 

二、json.loads()用法

1、例子

import json

data = {
"name": "Satyam kumar",
"place": "patna",
"skills": [
"Raspberry pi",
"Machine Learning",
"Web Development"
],
"email": "xyz@gmail.com",
"projects": [
"Python Data Mining",
"Python Data Science"
]
}
with open("data_file.json", "w") as write:
json.dump(data, write)

with open("data_file.json", "r") as read_content:
print(json.load(read_content))

 

2、Python和Json数据类型的映射

JSON Equivalent Python
object dict
array list
string str
number int
true True
false False
null None

 

 

三、json.load()用法

1、例子

import json

# JSON string:
# Multi-line string
data = """{
"Name": "Jennifer Smith",
"Contact Number": 7867567898,
"Email": "jen123@gmail.com",
"Hobbies":["Reading", "Sketching", "Horse Riding"]
}"""

# parse data:
res = json.loads(data)

# the result is a Python dictionary:
print(res)

 

四、写在最后

李先生(Lemon),高级运维工程师(自称),SRE专家(目标),梦想在35岁买一辆保时捷。喜欢钻研底层技术,认为底层基础才是王道。一切新技术都离不开操作系统(CPU、内存、磁盘)、网络等。坚持输入输出,记录自己学习的点滴,在平凡中坚持前行,总有一天会遇见不一样的自己。公众号:运维汪(ID:Leeeee_Li)。

 

有道词典
| JSON | Python ...
详细X
  JSON Python | | |   | - - - - - - - - - |:——:| | - - - - - - - - - - - -   | | dict对象   | |数组列表   | |字符串str   | | int数   |真|真   |假|假   零| |没有

相关文章:

  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-26
  • 2021-10-14
  • 2021-09-06
  • 2021-12-06
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案