2015-04-23 94 views
0

我有以下代碼:訪問從字典的字符串值

a= {'b': '{"c":46, "d": 1}', 'e': 10} 

這裏我需要在另一個字典中的字典的"c"價值,但'b'值是一本字典是在字符串格式。

在此先感謝.. !!

回答

0

你將不得不從JSON格式的字符串值解碼成這樣(使用python's json module)Python對象:

import json 

b_value = json.loads(a['b']) # decode the value from JSON string 
c_value = b_value['c'] # use/access the value 
+1

和蟒蛇2.7 JSON文檔https://docs.python.org/ 2 /庫/ json.html – Morb