美文网首页
python 字典转json字符串

python 字典转json字符串

作者: 觉释 | 来源:发表于2020-09-18 08:47 被阅读0次

import  json
aItem = {}
aItem["one"] = 1
aItem["two"] = 2
aItem["three"] = 3
aItem["four"] = "a"
aItem["five"] ="b"
 

aJson = json.dumps(aItem)
print aJson
 
输出
 
{"four": "a", "three": 3, "five": "b", "two": 2, "one": 1}
import  json
aItem = {}
aItem["one"] = 1
aItem["two"] = 2
aItem["three"] = 3
aItem["four"] = "a"
aItem["five"] ="b"
aItem["six"] = {"c1":"c1","c2":"c2"}

aJson = json.dumps(aItem)
print aJson

输出:
{"six": {"c2": "c2", "c1": "c1"}, "three": 3, "two": 2, "four": "a", "five": "b", "one": 1}

相关文章

网友评论

      本文标题:python 字典转json字符串

      本文链接:https://www.haomeiwen.com/subject/dcbksktx.html