1. 程式人生 > >json資料,字典和字串相互轉換

json資料,字典和字串相互轉換

text = {"name":"Jack","age":29}
read_json = json.loads(text)      # 把字典轉換為json
print(read_json)
print(type(read_json))

result = json.dumps(read_json)   # 把字典轉為str
print(result )
print(type(result ))

結果

{'name': 'Jack', 'age': 29}
<class 'dict'>
{"name": "Jack", "age": 29}
<class 'str'>