2012-11-06 76 views
0
[{"changed_aspect": "media", "subscription_id": xxxx, "object": "user", "object_id": "xxxx", "time": "xxxxxx"}] 

這是我從服務器獲得的數據。如何在python中將原始json對象轉換爲Json?

jsondump =傳入json.dump(數據)

但是當我jsondump [1] [ 「changed_aspect」]它不顯示的值的介質。我哪裏錯了?

+0

你會得到什麼錯誤? – Tim

+5

如果您將該[[1]]更改爲[[0]],該怎麼辦? – agf

回答

4

假設subscription_id應該是一個有效的字符串,

>>> import json 
>>> c = '[{"changed_aspect": "media", "subscription_id": "xxxx", "object": "user", "object_id": "xxxx", "time": "xxxxxx"}]' 
>>> data = json.loads(c) 
>>> data[0]['changed_aspect'] 
u'media' 

指數應爲0,而不是1,在python列表是基於0索引。