首页后端开发Pythonpython – python – json

python – python – json

时间2023-04-21 23:27:01发布访客分类Python浏览490
导读:直接看示例import json # 1.列表嵌套字典转json data = [{"a": "1"}, {"b": "2"}, {"c": "3"}] json_str = json.dumps(data, ensure_ascii=F...

直接看示例

import json
# 1.列表嵌套字典转json
data = [{
"a": "1"}
, {
"b": "2"}
, {
"c": "3"}
]

json_str = json.dumps(data, ensure_ascii=False)

print(f"转换后的内容为 - {
json_str}
")

# 2.字典转json
data = {
"a": "1"}
, {
"b": "2"}
, {
"c": "3"}


json_str = json.dumps(data, ensure_ascii=False)

print(f"转换后的内容为 - {
json_str}
")

# 3.字符串转json

s = '[{
"a": "1"}
, {
"b": "2"}
, {
"c": "3"}
]'

json_str = json.loads(s)

print(f"转换后的内容为 - {
json_str}
    ")

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

pythonjson

若转载请注明出处: python – python – json
本文地址: https://pptw.com/jishu/4804.html
python – 异常捕获 python – pyecharts基础使用

游客 回复需填写必要信息