当使用 python 的 json 解析这个页面时: http://polygons.openstreetmap.fr/get_geojson.py?id=4738519 出现 Runtime error (ValueErrorException): No JSON object could be decoded 报错
当使用 python 的 json 解析这个页面时: http://polygons.openstreetmap.fr/get_geojson.py?id=4738519 出现 Runtime error (ValueErrorException): No JSON object could be decoded 报错
|
009694May 12, 2021 via Android
1
首先没有展示任何代码 几乎很难有人能凭空想象来帮你 。 其次这是 geojson 不过并不影响 json 包的解析 只是不便于使用
|
|
rationa1cuzzMay 12, 2021
2
不贴代码鬼知道你什么问题
>>> response = requests.get("http://polygons.openstreetmap.fr/get_geojson.py?id=4738519") >>> response_json=response.json() >>> response_json.get("type") 'GeometryCollection' |
|
3
@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 JSON object could be decoded |
|
ynkkdevMay 12, 2021
4
- -上古代码,快跑
|
|
zerofinyMay 12, 2021
6
使用 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() ``` |
|
no1xsyzyMay 12, 2021
7
你先看看 response.read() 出来个啥吧。
No JSON object could be decoded 基本就是空白字符串的意思。 |
|
no1xsyzyMay 12, 2021
9
@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' |
|
ALLROBOTMay 12, 2021
11
json decode ?是解码问题?
如果允许的话,请使用 python3.6,毕竟 python2 太老了 |
|
ch2May 12, 2021
12
在网络编程的时候一定要注意先判断响应是否是 json 字符串,如果 http 请求异常,那么错误是在前一步而不是这一步
|