简体   繁体   中英

Python. How do I print specific value from json when from similiar names?

Okay so my problem is that I need to print out one specific value from a json. I've managed to print out all the values but not the specific one I want.

The json looks like this:

"apple": {
    "stuff": 111,
    "food": [
        {
            "money": 4000,
            "time": 36,
                    },
        {
            "money": 12210,
            "time": 94,

It continues like that with money and time. So my problem is that when I do this:

ourResult = js['apple']['food']
for rs in ourResult:
    print rs['time']

I receive all the times.. I only want to receive the time under money: 12210 for an example but I don't know how to do that when there is a colon and a value.

I thank you for all the help in advance.

Well, you already know how to get the value of "time", so just do the same with "money" and check it's equal to 12210.

Edit

for rs in ourResult:
    if rs['money'] == 12210:
        print rs['time']

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