简体   繁体   English

蟒蛇。 从相似名称中时,如何从json打印特定值?

[英]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. 好的,所以我的问题是我需要从json打印出一个特定值。 I've managed to print out all the values but not the specific one I want. 我设法打印出所有值,但没有打印出我想要的特定值。

The json looks like this: json看起来像这样:

"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. 我收到所有时间。.我只想收到金钱下的时间:例如12120,但是我不知道在有冒号和值的情况下该怎么做。

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. 好吧,您已经知道如何获取“时间”的值,因此只需对“金钱”进行同样的操作,并检查它等于12210。

Edit 编辑

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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