0

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.

2
  • According to your data, apple.stuff is an integer and can't be iterated over. Did you mean to do ourResult = js['apple']['food']? Commented Feb 1, 2014 at 20:40
  • Yes! Mistyped it in the thread. Commented Feb 1, 2014 at 20:48

1 Answer 1

3

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']
Sign up to request clarification or add additional context in comments.

5 Comments

I know how to get the value of all times, the thing I need is to get the value of time under "money": 12210,.
So do you know how to use an if statement?
As I'm a total beginner I would not say yes.
Well, that's a pretty fundamental thing not to know. You should really go and do an introductory tutorial. In the meantime, see my edit.
Thanks a lot, I've been following tutorials and I'm getting some help from my friend but now I know I need to focus more into the "basics of the basics". Anyways thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.