json 包 转字符串为dict json.loads(data_str)
import json # # 假设有一个 JSON 对象 # data = { # "name": "John", # "age": 30, # "city": "New York" # } # # # 将 JSON 对象转换为字符串 # json_str = json.dumps(data) # # print(json_str) # str 转json 类型是字典 data_str= '{"name": "John", "age": 30, "city": "New York"}' data_json=json.loads(data_str) print(type(data_json)) #<class 'dict'> print(data_json['name']) # 从字典中获取dict[key]=value John