当使用 python 的 json 解析这个页面时: http://polygons.openstreetmap.fr/get_geojson.py?id=4738519 出现 Runtime error (ValueErrorException): No JSON object could be decoded 报错
![]() | 1 009694 2021-05-12 11:32:23 +08:00 via Android 首先没有展示任何代码 几乎很难有人能凭空想象来帮你 。 其次这是 geojson 不过并不影响 json 包的解析 只是不便于使用 |
![]() | 2 rationa1cuzz 2021-05-12 11:37:06 +08:00 不贴代码鬼知道你什么问题 >>> respOnse= requests.get("http://polygons.openstreetmap.fr/get_geojson.py?id=4738519") >>> response_json=response.json() >>> response_json.get("type") 'GeometryCollection' |
3 wdc63 OP @009694 @rationa1cuzz 不好意思,我用的是 ironpython--py2.7,而且没法安装 requests 代码: respOnse= urllib2.urlopen(url, cOntext=context, timeout=self.timeout) place_info = json.loads(response.read()) 出错: Runtime error (ValueErrorException): No JSN object could be decoded |
4 youngce 2021-05-12 11:54:57 +08:00 - -上古代码,快跑 |
6 hasdream 2021-05-12 11:59:46 +08:00 使用 urllib2 也正常 ``` import json import urllib2 resp = urllib2.urlopen("http://polygons.openstreetmap.fr/get_geojson.py?id=4738519") resp_json = json.load(resp) print resp_json.keys() ``` |
![]() | 7 no1xsyzy 2021-05-12 12:03:42 +08:00 你先看看 response.read() 出来个啥吧。 No JSON object could be decoded 基本就是空白字符串的意思。 |
![]() | 9 no1xsyzy 2021-05-12 14:11:51 +08:00 @wdc63 临时跑去下了一个 IronPython 2.7,没发现任何问题。 >>> import json,urllib2 >>> url="http://polygons.openstreetmap.fr/get_geojson.py?id=4738519" >>> respOnse= urllib2.urlopen(url) >>> place_info = json.loads(response.read()) >>> place_info['type'] 'GeometryCollection' |
![]() | 11 ALLROBOT 2021-05-12 18:39:25 +08:00 json decode ?是解码问题? 如果允许的话,请使用 python3.6,毕竟 python2 太老了 |
![]() | 12 ch2 2021-05-12 18:46:54 +08:00 在网络编程的时候一定要注意先判断响应是否是 json 字符串,如果 http 请求异常,那么错误是在前一步而不是这一步 |