簡體   English   中英

Django使用嵌套字典反序列化JSON請求

[英]Django deserialize JSON request with nested dictionary

我具有以下命令來解析JSON請求而獲得的以下Python結構: request_data=json.loads(request.POST['request'])

{
    u'userID': u'123', 
    u'actions': {
        u'1': {u'notes': u'actionID= 35', u'actionType': u'7', u'currentTime': u'26/08/14'}, 
        u'0': {u'notes': u'bla bla', u'actionType': u'2', u'currentTime': u'26/08/14'}, 
        u'3': {u'notes': u'actionID= 31', u'actionType': u'7', u'currentTime': u'26/08/14'},  
        u'2': {u'notes': u'actionID= 14', u'actionType': u'7', u'currentTime': u'26/08/14'}, 
        u'5': {u'notes': u'actionID= 12', u'actionType': u'7', u'currentTime': u'26/08/14'}
    }
}

當我嘗試循環播放時,如何獲取注釋和動作類型

counter=0
for key in user_actions:
   value=user_actions[str(counter)]
   #how can I extract notes out of value???                  
   counter = counter +1

我試過了:

  • 價值筆記
  • 值['notes']
  • user_actions [key] ['notes']

這對我來說毫無意義,因為如果我輸出value我會得到內部字典{u'notes': u'actionID= 35', u'actionType': u'7', u'currentTime': u'26/08/14'}但使用相同的邏輯提取內部字典值不起作用

for k, v in user_actions.iteritems():
    print v['notes']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM