python将将JSON数据转换为字典
要将JSON数据转换为字典,可以使用json模块中的loads()函数。以下是一个示例:
import json
# JSON数据
json_data = '{"name": "John", "age": 30, "city": "New York"}'
# 将JSON数据转换为字典
dict_data = json.loads(json_data)
print(dict_data) # 输出:{'name': 'John', 'age': 30, 'city': 'New York'}
print(type(dict_data)) # 输出:<class 'dict'>
首先,导入json模块。然后,使用loads()函数将JSON数据转换为字典。最后,打印字典数据和字典数据的类型。
原文地址: https://www.cveoy.top/t/topic/iM3C 著作权归作者所有。请勿转载和采集!