小编bnl*_*cas的帖子

在Python中将字符串转换为JSON?

我正在尝试转换使用urllib3从http请求生成的字符串.

Traceback (most recent call last):
  File "<pyshell#16>", line 1, in <module>
    data = json.load(data)
  File "C:\Python27\Lib\json\__init__.py", line 286, in load
    return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'

>>> import urllib3
>>> import json
>>> request = #urllib3.request(method, url, fields=parameters)
>>> data = request.data
Run Code Online (Sandbox Code Playgroud)

现在......当尝试以下内容时,我得到了这个错误......

>>> json.load(data) # generates the error
>>> json.load(request.read()) # generates the error
Run Code Online (Sandbox Code Playgroud)

跑步type(data),type(data.read())都回归<type 'str'>

data = '{"subscriber":"0"}}\n'
Run Code Online (Sandbox Code Playgroud)

python json urllib3

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

json ×1

python ×1

urllib3 ×1