【发布时间】:2018-02-09 17:11:41
【问题描述】:
我正在尝试通过 json 解析 HTTP 响应,但它给了我字符错误,但是当我尝试通过 for 循环遍历此响应时,它会将所有内容拆分为单个字符。有没有更好的方法来解析这个响应?
代码:
_url = self.MAIN_URL
try:
_request = self.__webSession.get(_url, cookies=self.__cookies)
if _request.status_code != 200:
self.log("Request failed with code: {}. URL: {}".format(_request.status_code, _url))
return
except Exception as err:
self.log("[e4] Web-request error: {}. URL: {}".format(err, _url))
return
_text = _request.json()
json.loads() 返回以下
Expecting value: line 1 column 110 (char 109)
需要解析HTTP响应:
[
[
9266939,
'Value1',
'Value2',
'Value3',
,
'Value4',
[
[
'number',
'number2',
[
'value',
,
'value2'
]
]
]
],
[
5987798,
'Value1',
'Value2',
,
'Value3',
'Value4',
[
[
'number',
'number2',
[
'value',
'value2'
]
]
]
]
]
【问题讨论】:
-
您可以使用 json.loads 函数从您的 json 文本字符串中获取类似 python 的对象。 docs.python.org/3/library/json.html
-
不能,它返回 - 期望值:第 1 行第 110 列(字符 109)
-
在这个 url 中检查你的 http 响应:json check;
标签: python json python-3.x http parsing