从 GeocoderResponse 中提取坐标
Extracting coordinates from GeocoderResponse
我正在尝试使用 Herepy 中的 Free_form 方法获取位置坐标。这个函数 returns 一个 Json 形式的数据列表(据我所知)。我想从此列表中提取某些数据。我尝试使用 json.loads() 但它 returns 出现以下错误:
TypeError: the JSON object must be str, bytes or bytearray, not 'GeocoderResponse'
数据如下所示:
{"Response": {"MetaInfo": {"Timestamp": "2019-06-02T16:46:46.588+0000"}, "View": [{"Result": [{"Location": {"Address":{"AdditionalData": [{"key": "CountryName", "value": "Nederland"}, {"key": "StateName", "value": "Noord-Holland"}, {"key": "CountyName", "value": "Haarlemmermeer"}], "City": "Nieuw-Vennep", "Country": "NLD", "County": "Haarlemmermeer", "Label": "Nieuw-Vennep, Noord-Holland, Nederland", "PostalCode": "2151 AR", "State": "Noord-Holland"}, "DisplayPosition":{"Latitude": 52.26388, "Longitude": 4.62986}, "LocationId": "NT_.gc2w3DtLRjNeEZj3hDvIB", "LocationType": "point", "MapView": {"BottomRight": {"Latitude": 52.25047, "Longitude": 4.65622}, "TopLeft": {"Latitude": 52.28503, "Longitude": 4.59986}}, "NavigationPosition": [{"Latitude": 52.26388, "Longitude": 4.62986}]}, "MatchLevel": "city", "MatchQuality": {"City": 0.5}, "Relevance": 1.0}], "ViewId": 0, "_type": "SearchResultsViewType"}]}}
或...
{'Response': {'MetaInfo': {'Timestamp': '2019-06-02T16:46:46.588+0000'},
'View': [{'Result': [{'Location': {'Address': {'AdditionalData': [{'key': 'CountryName',
'value': 'Nederland'},
{'key': 'StateName',
'value': 'Noord-Holland'},
{'key': 'CountyName',
'value': 'Haarlemmermeer'}],
'City': 'Nieuw-Vennep',
'Country': 'NLD',
'County': 'Haarlemmermeer',
'Label': 'Nieuw-Vennep, '
'Noord-Holland, '
'Nederland',
'PostalCode': '2151 '
'AR',
'State': 'Noord-Holland'},
'DisplayPosition': {'Latitude': 52.26388,
'Longitude': 4.62986},
'LocationId': 'NT_.gc2w3DtLRjNeEZj3hDvIB',
'LocationType': 'point',
'MapView': {'BottomRight': {'Latitude': 52.25047,
'Longitude': 4.65622},
'TopLeft': {'Latitude': 52.28503,
'Longitude': 4.59986}},
'NavigationPosition': [{'Latitude': 52.26388,
'Longitude': 4.62986}]},
'MatchLevel': 'city',
'MatchQuality': {'City': 0.5},
'Relevance': 1.0}],
'ViewId': 0,
'_type': 'SearchResultsViewType'}]}}
查看 the documentation,一个 GeocoderResponse
对象应该有一个 as_dict
方法,它应该给你想要的东西。它还应该有一个 as_json_string
方法,你可以使用 json.loads
- stuff=json.loads(gr_obj.as_json_string)
.
我正在尝试使用 Herepy 中的 Free_form 方法获取位置坐标。这个函数 returns 一个 Json 形式的数据列表(据我所知)。我想从此列表中提取某些数据。我尝试使用 json.loads() 但它 returns 出现以下错误:
TypeError: the JSON object must be str, bytes or bytearray, not 'GeocoderResponse'
数据如下所示:
{"Response": {"MetaInfo": {"Timestamp": "2019-06-02T16:46:46.588+0000"}, "View": [{"Result": [{"Location": {"Address":{"AdditionalData": [{"key": "CountryName", "value": "Nederland"}, {"key": "StateName", "value": "Noord-Holland"}, {"key": "CountyName", "value": "Haarlemmermeer"}], "City": "Nieuw-Vennep", "Country": "NLD", "County": "Haarlemmermeer", "Label": "Nieuw-Vennep, Noord-Holland, Nederland", "PostalCode": "2151 AR", "State": "Noord-Holland"}, "DisplayPosition":{"Latitude": 52.26388, "Longitude": 4.62986}, "LocationId": "NT_.gc2w3DtLRjNeEZj3hDvIB", "LocationType": "point", "MapView": {"BottomRight": {"Latitude": 52.25047, "Longitude": 4.65622}, "TopLeft": {"Latitude": 52.28503, "Longitude": 4.59986}}, "NavigationPosition": [{"Latitude": 52.26388, "Longitude": 4.62986}]}, "MatchLevel": "city", "MatchQuality": {"City": 0.5}, "Relevance": 1.0}], "ViewId": 0, "_type": "SearchResultsViewType"}]}}
或...
{'Response': {'MetaInfo': {'Timestamp': '2019-06-02T16:46:46.588+0000'},
'View': [{'Result': [{'Location': {'Address': {'AdditionalData': [{'key': 'CountryName',
'value': 'Nederland'},
{'key': 'StateName',
'value': 'Noord-Holland'},
{'key': 'CountyName',
'value': 'Haarlemmermeer'}],
'City': 'Nieuw-Vennep',
'Country': 'NLD',
'County': 'Haarlemmermeer',
'Label': 'Nieuw-Vennep, '
'Noord-Holland, '
'Nederland',
'PostalCode': '2151 '
'AR',
'State': 'Noord-Holland'},
'DisplayPosition': {'Latitude': 52.26388,
'Longitude': 4.62986},
'LocationId': 'NT_.gc2w3DtLRjNeEZj3hDvIB',
'LocationType': 'point',
'MapView': {'BottomRight': {'Latitude': 52.25047,
'Longitude': 4.65622},
'TopLeft': {'Latitude': 52.28503,
'Longitude': 4.59986}},
'NavigationPosition': [{'Latitude': 52.26388,
'Longitude': 4.62986}]},
'MatchLevel': 'city',
'MatchQuality': {'City': 0.5},
'Relevance': 1.0}],
'ViewId': 0,
'_type': 'SearchResultsViewType'}]}}
查看 the documentation,一个 GeocoderResponse
对象应该有一个 as_dict
方法,它应该给你想要的东西。它还应该有一个 as_json_string
方法,你可以使用 json.loads
- stuff=json.loads(gr_obj.as_json_string)
.