python字典与JSON字符串如何互相转换:
1.python字典转换成JSON字符串:
import json
a = {"a": 1, "b": 2, "c": 3} #字典
print(a)
b = json,dump(a) #JSON字符串
print(b)
"""结果:
{"a": 1, "b": 2, "c": 3}
{"a": 1, "b": 2, "c": 3} """
2.JSON字符串转换成python字典:
import json
a = json,dump({"a": 1, "b": 2, "c": 3}) #JSON字符串
print(a)
b = json.ioads(a) #字典
print(b)
"""结果:
{"a": 1, "b": 2, "c": 3}
{"a": 1, "b": 2, "c": 3} """