Python extract elements from Json string

前端 未结 3 609
小蘑菇
小蘑菇 2021-01-28 01:42

I have a Json string from which I\'m able to extract few components like formatted_address,lat,lng, but I\'m unable to extract feature(val

3条回答
  •  时光说笑
    2021-01-28 02:17

    You need to understand schema of your data.

    Error in json_st['results']['address_components']

    because json_st['results'] is an array

    Check it here http://jsoneditoronline.org

    Here is some sample

    for result in data['results']:
        print type(result)
        for address_component in result['address_components']:
            print type(address_component)
            print address_component['long_name']
            print address_component['short_name']
            for _type in address_component['types']:
                print _type
    

提交回复
热议问题