简体   繁体   中英

Iterate over JSON objects in Python

I get JSON from firebase (simplified):

logitems = {
u'-K7w56QCnpYI': { u'Date': 1452707179865.0618, u'Message': 'messagetest1' },
u'-K7w56safnpYI': { u'Date': 1452707179867.0618, u'Message': 'messagetest2' },
u'-FSDFSDddsfsI': { u'Date': 1452707179868.0618, u'Message': 'messagetest3' },
}

How can I iterate over the items (stored with keys instead in an array)?

I think you want to reference your items as shown in this post here.

Converting JSON String to Dictionary Not List

Then you can wrap your iteration in a for loop.

正确的答案来自Rogalski的评论:

for v in logitems.values()? .itervalues() for Py2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM