Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

JSON From HTTP Print Value With Python

$
0
0

Thank you in advance for your help - I have been searching for hours.

Forgive me if I use the wrong terminology.

I'm grabbing JSON from an http link. I can print the entire json string, and I can print all of the key values. What I'm trying to do is to get only certain values based on an ID.

Json output:

{"common_list": [  {"id": "0x0B","val": "3.58 mph"  },  {"id": "0x0C","val": "5.82 mph"  },  {"id": "0x19","val": "15.88 mph"  },  {"id": "0x15","val": "519.26 W/m2"  },  {"id": "0x17","val": "4"  },  {"battery": "5","id": "0x0A","val": "243"  }]

As I said I can print all "id" or all "val", but I want to return the "val" for a single "id". I hope that makes sense. Here is code I have to print all "id":

import jsonfrom urllib.request import urlopenurl = 'http://ecowitt/get_livedata_info'resp = urlopen(url)data = json.loads(resp.read())dicts = data['common_list']for dict in dicts:    print(dict["id"])

Output:0x020x0730x030x0B0x0C0x190x150x170x0A

Now I want to print "val" for say "0x0B". That is where I'm stuck. Thank you!


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>