JSON字符串如何转换成Python?
发布时间:2024-08-08 16:02:03

一、JSON介绍
JSON表示,JAVA小号scriptobjectn浮选以有组织、简单的方式存储信息。当浏览器和服务器之间交换数据时,数据必须是文本格式。
二、JSON字符串转换Python
1.使用以下代码示例
importjson
people_string='''
{
"people":[
{
"emp_name":"Johnsmith",
"emp_no.":"924367-567-23",
"emp_email":["johnsmith@dummyemail.com"],
"has_license":"false"
},
{
"emp_name":"harshitkant",
"emp_number":"560-555-5153",
"emp_email":"null",
"has_license":"true"
}
]
}
'''
data=json.loads(people_string)
print(data)2.输出

3.打印数据类型
importjson
people_string='''
{
"people":[
{
"emp_name":"Johnsmith",
"emp_no.":"924367-567-23",
"emp_email":["johnsmith@dummyemail.com"],
"has_license":"false"
},
{
"emp_name":"harshitkant",
"emp_number":"560-555-5153",
"emp_email":"null",
"has_license":"true"
}
]
}
'''
data=json.loads(people_string)
print(type(data))#printsthedatatype输出:
<class'dict'>
JSON相关知识点学习推荐阅读:
json和python字典的区别
Python中Json模块的用法及介绍
下一篇 python 图像灰度处理
