[問題] string轉dict格式

看板Python作者 (京)時間9年前 (2016/11/02 11:17), 編輯推噓1(104)
留言5則, 5人參與, 最新討論串1/1
請問有模組可以把下面這段string轉成dict格式嗎? (dict中的dict和list也要一併轉換成dict和list) 謝謝 '{ "dpid": 1, "cookie": 1, "cookie_mask": 1, "table_id": 0, "idle_timeout": 30, "hard_timeout": 30, "priority": 11111, "flags": 1, "match":{ "in_port" : 1 }, "actions": [ { "type":"OUTPUT", "port": 2 } ] }' -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.228.145.178 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1478056653.A.9C6.html

11/02 11:22, , 1F
eval
11/02 11:22, 1F

11/02 11:58, , 2F
去除換行字元後用 json 內的 json.loads 讀入即可
11/02 11:58, 2F

11/02 12:17, , 3F
json.loads
11/02 12:17, 3F

11/02 18:23, , 4F
感謝樓上諸位
11/02 18:23, 4F

11/02 20:52, , 5F
OVS 嗎 XD
11/02 20:52, 5F
文章代碼(AID): #1O6LhDd6 (Python)
文章代碼(AID): #1O6LhDd6 (Python)