我正在尝试使用Herepy中的Free_form方法获取位置的坐标。这个函数以Json的形式返回一个数据列表(据我所知)。我想从这个列表中提取某些数据。我尝试使用json.loads(),但它返回以下错误:
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'}]}}发布于 2019-06-03 01:41:35
通过the documentation查看,GeocoderResponse对象应该有一个as_dict方法,它应该给你想要的东西。它还应该有一个可以与json.loads - stuff=json.loads(gr_obj.as_json_string)一起使用的as_json_string方法。
https://stackoverflow.com/questions/56416549
复制相似问题