解析我试图解析这个小JSON,我想借此数量:JSON与Python
{"nombre":18747}
我尝试:
import urllib.request
request = urllib.request.Request("http://myurl.com")
response = urllib.request.urlopen(request)
print (response.read().decode('utf-8')) //print -> {"nombre":18747}
import json
json = (response.read().decode('utf-8'))
json.loads(json)
但我有:
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
json.loads('json')
AttributeError: 'str' object has no attribute 'loads'
任何帮助?
是的,但我有这样的:文件“C:\ Python33 \ lib \ json \ decoder.py”,行352,解码 obj,结束= self.raw_decode(s,idx = _w(s,0)。 ()) TypeError:不能在类似字节的对象上使用字符串模式 – mpgn
@Martialp:啊,我明白了;这改变了Python 3.我会更新。 –
是的,现在我有:ValueError:没有JSON对象可以被解码 – mpgn