我正在尝试使用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'}]}}
答案 0 :(得分:0)
浏览the documentation时,GeocoderResponse
对象应具有一个as_dict
方法,该方法应该可以让您找到想要的对象。它还应该具有as_json_string
-json.loads
可以使用的stuff=json.loads(gr_obj.as_json_string)
方法。