python中常见的转义字符格式详见博文:python中常用的转义字符_IT之一小佬的博客-CSDN博客
案例分析:
给定下述字典格式:
{'name': 'zhangsan', 'age': '25'}
输出为下述格式:
["{\"name\":\"zhangsan\"}", "{\"age\":\"25\"}"]
示例代码:
import jsondic = {'name': 'zhangsan', 'age': '25'}data = []
for key, value in dic.items():ret = "{" + "\"" + key + "\"" + ":" + "\"" + value + "\"}"print(ret)data.append(ret)
print(data)
print(str(data))
print(json.dumps(data))
运行结果: