我正在使用 python 使用 Directions API。
mapApi = GoogleMaps(API_KEY)
directionsObj.routes = mapApi.directions(directionsObj.source, directionsObj.destination)
print "directionsObj.routesssss", directionsObj.routes['routes']
我使用上面的代码来获取 Directions API 的 Json 响应文件,并将 Json 存储到 mongoengine(使用的数据库)。现在在终端中,当我运行上述代码时,我得到以下结果。
json文件:
[{u'overview_polyline': {u'points': u'yiv{@a~~pMPv@KDRnAfAdHeBl@o@ZaAh@}Bx@}CdAyBn@oDfAgEtAv@pEpBbLlBnItCxMlBlHdBpGzB|HXhAl@tBXv@`@`AoAr@iKbF{CxAcAl@]T_@^Q^GVIf@UdAO`@[j@YXo@b@aCrAsAn@{IhD{At@yCfBqAv@_@\\kAxByErKeB|DKR_CzCsBhCcAfAk@h@[Re@Js@JgD\\aBFeAAcAIq@OqAe@}@Qg@Ce@Bs@Ls@Ts@r@s@~@k@hAmCHeDDkAFsBJkI`@_BJyG\\s^bB}QvAa\\xCcEZaGl@yCV_Q~ABNh@Et@bBDVCJ?XL|@X`AXz@Rd@^r@`@t@X|@F^Dt@Jt@Xf@NTPl@Ff@?j@VnBJr@I@MFu@d@YPy@\\{Bl@}Aj@e@Vw@`@WFW@c@?a@E{@IU?q@JwB`@oB`@cARyABaCFs@FaAJOBbAnE?VEl@E^BRvAfCJJLFjAf@QDgEbAqAPoB^}@JkAReCl@iAZsBZGDCJDh@EDaD^Rv@b@bC\\tBVxB\\xCPdAPl@\\jAXv@zBvChAtAr@~@dCpC'}, u'copyrights': u'Map data \xa92012 Google', u'warnings': [], u'legs': [{u'distance': {u'text': u'11.1 km', u'value': 11118}, u'end_address': u'Kaloor, Ernakulam, Kerala, India', u'via_waypoint': [], u'start_address': u'Thrippunithura, Kerala, India', u'duration': {u'text': u'19 mins', u'value': 1126}, u'steps': [{u'html_instructions': u'Head west', u'distance': {u'text': u'33 m', u'value': 33}, u'polyline': {u'points': u'yiv{@a~~pMPv@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949890000000002, u'lng': 76.34929000000001}, u'duration': {u'text': u'1 min', u'value': 4}, u'end_location': {u'lat': 9.949800000000003, u'lng': 76.34901}}, {u'html_instructions': u'Turn right toward Ernakulam-Ettumanoor Rd/SH 15', u'distance': {u'text': u'8 m', u'value': 8}, u'polyline': {u'points': u'giv{@i|~pMKD'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949800000000003, u'lng': 76.34901}, u'duration': {u'text': u'1 min', u'value': 11}, u'end_location': {u'lat': 9.949860000000001, u'lng': 76.34898000000001}}, {u'html_instructions': u'Take the 1st left toward Ernakulam-Ettumanoor Rd/SH 15', u'distance': {u'text': u'0.2 km', u'value': 211}, u'polyline': {u'points': u'siv{@c|~pMJp@F\\D\\RjA^|BL|@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949860000000001, u'lng': 76.34898000000001}, u'duration': {u'text': u'1 min', u'value': 28}, u'end_location': {u'lat': 9.949400000000002, u'lng': 76.34711}}, {u'html_instructions': u'Turn right onto Ernakulam-Ettumanoor Rd/SH 15Pass by Abhayam (on the right in 400m)', u'distance': {u'text': u'0.6 km', u'value': 608}, u'polyline': {u'points': u'wfv{@mp~pMcA\\a@N[NSJg@VYP[LaBj@m@PoBr@{@V}@V}Bp@q@T]JiDhA'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949400000000002, u'lng': 76.34711}, u'duration': {u'text': u'1 min', u'value': 71}, u'end_location': {u'lat': 9.95439, u'lng': 76.34486000000001}}, {u'html_instructions': u'Turn left at SN Jct onto Kochi - Madurai - Tondi Point Hwy/Kochi - Madurai - Tondi Point Highway/NH 85Pass by ICICI Bank (on the left)', u'distance': {u'text': u'1.5 km', u'value': 1536}, u'polyline': {u'points': u'}ew{@kb~pM@D^xBTnA?@pB`L?@x@xDr@tCJf@x@zDJd@bAnEj@xBBJDNv@vCT|@b@|ABJf@hB~@zCz@`DJ\\Lj@^rAL`@JXL\\FRXl@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.95439, u'lng': 76.34486000000001}, u'duration': {u'text': u'2 mins', u'value': 112}, u'end_location': {u'lat': 9.949900000000001, u'lng': 76.33162}}, {u'html_instructions': u'Turn right at Petta Jct onto Ernakulam Ettumanoor Rd', u'distance': {u'text': u'54 m', u'value': 54}, u'polyline': {u'points': u'{iv{@so{pMo@^_@R'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949900000000001, u'lng': 76.33162}, u'duration': {u'text': u'1 min', u'value': 59}, u'end_location': {u'lat': 9.9503, u'lng': 76.33136}}, {u'html_instructions': u'Continue onto SH 15 Ernakulam -Ettumanoor HwyPass by Reliance Petrol Pump (on the right in 1.5km)', u'distance': {u'text': u'2.5 km', u'value': 2516}, u'polyline': {u'points': u'klv{@_n{pMuBbAcBx@uBbAy@`@OFqAn@g@TQJWLOJQJIFEBC@KHGDGFGFGDGHEFEHA@CJEJAJEPCTKh@IZGRGLIPGHABGJIHONIFe@ZMFe@Vi@Zc@VQHULSHWLs@XaEzA{An@IBe@Tu@^}@h@{A|@WNMHYPQJKHKHCBCDEFKP]n@[n@e@dAQ\\s@`BmBlEg@hAe@dAO\\GNEHEHEFyBrCmA~Ae@h@_@`@c@d@[XONKHOHSDQDWF[BcALcBNy@Bg@Bi@?[A]Ce@E]GSGk@Se@QOESEMCKAUAQAS@Q@YDYFWH[J'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.9503, u'lng': 76.33136}, u'duration': {u'text': u'3 mins', u'value': 153}, u'end_location': {u'lat': 9.967500000000001, u'lng': 76.31912000000001}}, {u'html_instructions': u'Continue onto Sahodaran Ayyappan Rd', u'distance': {u'text': u'0.1 km', u'value': 134}, u'polyline': {u'points': u'{wy{@oaypMGHIFQPONKJQTKNILa@t@IR'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.967500000000001, u'lng': 76.31912000000001}, u'duration': {u'text': u'1 min', u'value': 59}, u'end_location': {u'lat': 9.968240000000002, u'lng': 76.31817000000001}}, {u'html_instructions': u'Turn right at Vyttila Jct onto NH 66Pass by Muthoot Motors (on the left in 1.6km)', u'distance': {u'text': u'2.8 km', u'value': 2771}, u'polyline': {u'points': u'o|y{@q{xpMS?yBHeDDkAFm@BeAFgCJcEToAHO@yEVo@DC?K?q@DK@qLh@cOp@wIn@OB}ALwCTmNpA{D\\qEb@e@DcEZaGl@sAJeAJuALcFb@yEd@k@F'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.968240000000002, u'lng': 76.31817000000001}, u'duration': {u'text': u'3 mins', u'value': 205}, u'end_location': {u'lat': 9.99295, u'lng': 76.31493}}, {u'html_instructions': u'Turn left toward NH66 Service Road', u'distance': {u'text': u'9 m', u'value': 9}, u'polyline': {u'points': u'}v~{@igxpM?@BL'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.99295, u'lng': 76.31493}, u'duration': {u'text': u'1 min', u'value': 11}, u'end_location': {u'lat': 9.992930000000001, u'lng': 76.31485}}, {u'html_instructions': u'Turn left onto NH66 Service Road', u'distance': {u'text': u'24 m', u'value': 24}, u'polyline': {u'points': u'yv~{@yfxpMd@EB?'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.992930000000001, u'lng': 76.31485}, u'duration': {u'text': u'1 min', u'value': 11}, u'end_location': {u'lat': 9.99272, u'lng': 76.31488}}, {u'html_instructions': u'Take the 1st right onto Puthiya Rd', u'distance': {u'text': u'0.6 km', u'value': 621}, u'polyline': {u'points': u'ou~{@_gxpMBFh@jABHBD@F@F?D@@?@?@A@AD?B?F?D?F?D@BHj@@F?BDJHVHXPh@FPHTHNP^LRRXLZFPDJDLDPBLBPB\\@V@N@LBJBJ@BFJHLDHBFJLFTHV@F@B@L@L?H?J?H?J@NBTLv@BPJr@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.99272, u'lng': 76.31488}, u'duration': {u'text': u'1 min', u'value': 51}, u'end_location': {u'lat': 9.990900000000002, u'lng': 76.30962000000001}}, {u'html_instructions': u'Turn right at Puthiya Road Junction onto Thammanam RdPass by Thammanam Mosque (on the left)', u'distance': {u'text': u'0.6 km', u'value': 623}, u'polyline': {u'points': u'cj~{@cfwpMI@GBEBOJOHIFKFKHMFg@RQHWH[Ha@He@No@Tm@TYNKFQHSLGBIDMBIBK@K?S?O?OAQC]E]CIAK@I@OBMBI@_APw@NoAT_@JQDYFKBK@S?'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.990900000000002, u'lng': 76.30962000000001}, u'duration': {u'text': u'2 mins', u'value': 98}, u'end_location': {u'lat': 9.996120000000001, u'lng': 76.30793000000001}}, {u'html_instructions': u'Continue onto Mahakavi Vailoppilli Rd', u'distance': {u'text': u'0.2 km', u'value': 187}, u'polyline': {u'points': u'wj_|@q{vpMa@@Q?Q@eBB[BYBYB_@Da@DOB'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.996120000000001, u'lng': 76.30793000000001}, u'duration': {u'text': u'1 min', u'value': 42}, u'end_location': {u'lat': 9.99779, u'lng': 76.30775000000003}}, {u'html_instructions': u'Turn left onto Indira Road', u'distance': {u'text': u'0.3 km', u'value': 343}, u'polyline': {u'points': u'eu_|@mzvpMbAnE@JAJC^ALEX?D@F@JBFrA~BDDDDFBDBjAf@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.99779, u'lng': 76.30775000000003}, u'duration': {u'text': u'1 min', u'value': 45}, u'end_location': {u'lat': 9.996540000000001, u'lng': 76.30512}}, {u'html_instructions': u'Turn right onto St. Martin Road', u'distance': {u'text': u'0.6 km', u'value': 641}, u'polyline': {u'points': u'km_|@_jvpMQDgEbAqAP_@FoAVI@s@HkAReCl@m@P[Hc@HoAPC@CBADADDb@?DABC@aD^'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.996540000000001, u'lng': 76.30512}, u'duration': {u'text': u'1 min', u'value': 89}, u'end_location': {u'lat': 10.00178, u'lng': 76.30334}}, {u'html_instructions': u'Turn left at Worldwide IPR Services onto NH 47Pass by Juma Masjid (on the left)Destination will be on the left', u'distance': {u'text': u'0.8 km', u'value': 799}, u'polyline': {u'points': u'cn`|@{~upMRv@RnANr@BRX`BRxAB^D`@P~ABP@DF^Hd@@DNf@Rp@HXHXN\\`@j@xAjBJL|@fAr@~@dCpC'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 10.00178, u'lng': 76.30334}, u'duration': {u'text': u'1 min', u'value': 77}, u'end_location': {u'lat': 9.998700000000001, u'lng': 76.29695000000001}}], u'start_location': {u'lat': 9.949890000000002, u'lng': 76.34929000000001}, u'end_location': {u'lat': 9.998700000000001, u'lng': 76.29695000000001}}], u'bounds': {u'northeast': {u'lat': 10.00178, u'lng': 76.34929000000001}, u'southwest': {u'lat': 9.949400000000002, u'lng': 76.29695000000001}}, u'waypoint_order': [], u'summary': u'NH 66'}]
如何解析上面的 Json 文件,以便我只能得到start_address
, end_address
, u'html_instructions
only。