1. 程式人生 > >python str dic json 字串轉化為字典

python str dic json 字串轉化為字典

1,python資料轉換為json資料

#!/usr/local/bin/python3
# coding:utf-8
import json
data = '{"name": "ni", "city": "tt", "id" : 2256}'
print (data)
print (type(data))
#print (data['name'])
json_str = json.loads(data)
print (type(json_str))
print (json_str['name'])
print ("測試") 
{"name": "ni", "city": "tt", "id" : 2256}
<class 'str'>
<class 'dict'>
ni
測試

  • 報錯,data裡面字串必須使用雙引號

Expecting property name enclosed in double quotes

參考: