python 字典转json字符串

2020-09-18  本文已影响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}
上一篇 下一篇

猜你喜欢

热点阅读