how can i use a json output in python -
i trying figure out how json
output in python
. here url:
whose output this
{ "status": "ok", "origin_addresses": [ "vancouver, bc, canada", "seattle, État de washington, États-unis" ], "destination_addresses": [ "san francisco, californie, États-unis", "victoria, bc, canada" ], "rows": [ { "elements": [ { "status": "ok", "duration": { "value": 340110, "text": "3 jours 22 heures" }, "distance": { "value": 1734542, "text": "1 735 km" } }, { "status": "ok", "duration": { "value": 24487, "text": "6 heures 48 minutes" }, "distance": { "value": 129324, "text": "129 km" } } ] }, { "elements": [ { "status": "ok", "duration": { "value": 288834, "text": "3 jours 8 heures" }, "distance": { "value": 1489604, "text": "1 490 km" } }, { "status": "ok", "duration": { "value": 14388, "text": "4 heures 0 minutes" }, "distance": { "value": 135822, "text": "136 km" } } ] } ] }
how can print output in python ?
can me out ?
thanks
depending on version of python, importing json might not enough.
if running version of python less 2.6, need install simplejson commandline.
pip install simplejson
after that, import normally.
import simplejson json
the following should work in python 2.x. there few differences in 3.x, i'll leave exercise imagination.
try: import json except: import simplejson json url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=vancouver+bc|seattle&destinations=san+francisco|victoria+bc&mode=bicycling&language=fr-fr&sensor=false" contents = urllib2.urlopen(url).read() json_array = json.loads(contents) print repr(json_array)
Comments
Post a Comment