如何在python中从json响应中获取元素

如何在python中从json响应中获取元素,python,python-3.x,django,python-2.7,Python,Python 3.x,Django,Python 2.7,在python中,我得到的响应如下: {'destination_addresses': ['402, I Park, Plot No. 15], 'origin_addresses': [Sector 19, Haryana 122008, India'], 'rows': [{'elements': [{'distance': {'text': '1.7 km', 'value': 1672}, 'duration': {'text': '6 mins', 'value': 342}, 'd

在python中,我得到的响应如下:

{'destination_addresses': ['402, I Park, Plot No. 15], 'origin_addresses': [Sector 19, Haryana 122008, India'], 'rows': [{'elements': [{'distance': {'text': '1.7 km', 'value': 1672}, 'duration': {'text': '6 mins', 'value': 342}, 'duration_in_traffic': {'text': '6 mins', 'value': 334}, 'status': 'OK'}]}], 'status': 'OK'}

我想得到距离内的值我怎么能得到这个值有人能帮我联系一下吗???

你有嵌套的数组结构,所以,假设你正在使用
请求
,然后:

json = response.json()

for r in json['rows']:
    for e in r['elements']:
        print(e['distance'])

Thanx它对我很有用,但我不想用任何方式感谢你这么多
dictionary = {
  'destination_addresses': [
    '402, I Park, Plot No. 15], 'origin_addresses': [Sector 19, Haryana 122008, India'
  ],
  'rows': [
    {
      'elements': [
        {
          'distance': {
            'text': '1.7 km',
            'value': 1672
          },
          'duration': {
            'text': '6 mins',
            'value': 342
          },
          'duration_in_traffic': {
            'text': '6 mins',
            'value': 334
          },
          'status': 'OK'
        }
      ]
    }
  ],
  'status': 'OK'
}

print(dictionary['rows'][0]['elements'][0]['distance'])