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

 

posted @ 2023-07-25 11:58  胖豆芽  阅读(15)  评论(0编辑  收藏  举报