decoding json dictionary with python

后端 未结 2 616
小鲜肉
小鲜肉 2021-01-29 14:21

Ive got a script written to fetch data from an API, and return it, but now i need to parse that data, this is an example of what the json data looks like, with some of the dicti

2条回答
  •  梦毁少年i
    2021-01-29 14:24

    It sounds like you want something like this:

    def call():
        payload = {'apikey':'my_apikey', 'zip':'74120'}
        bas_url = 'http://openstates.org/api/v1//legislators/?state=ok'
        r = requests.get(bas_url, params = payload)
        grab = r.json()
        jsonData = grab["results"]
        return [{key: value for key, value in result.items() if key in ("twitter_id", "office")} for result in jsonData]
    

提交回复
热议问题