我正在尝试访问特定的json数据,下面是代码。即时通讯使用python 2.7。但它出现错误 TypeError:字符串索引必须是整数:
http = win32com.client.Dispatch('MSXML2.XMLHTTP.6.0')
http.open('POST', 'url', False, username, password)
http.setRequestHeader("Content-type" , "text/json" )
http.setRequestHeader("User-Agent" , "Your User Agent String")
http.setRequestHeader("Accept-Encoding" , "gzip, deflate" )
http.setRequestHeader("Content-Encoding", "gzip, deflate" )
global data
http.send(json)
global data
data = http.responseText
#data=data.split("{}{}") -try to make json data print nicely but failed.
print data['responses'][0]['status']
我的json数据如下
{
"responses": [
{
"tran_id": "1234",
"UUID": "122262d7-85f8-4e53-af98-865627cb82cb",
"status": "success",
"messages": [],
"result_params": {
"record_count": "1"
},
"result_table": [
{
"id": "101160766",
"rev": "13",
"hierarchy_id": "F80005AF46FF0000B5EA6FE06078159E80",
"is_current": "1"}}
,
答案 0 :(得分:0)
答案 1 :(得分:0)
a)您的"内容类型"标题字段不正确。它应该是application / json。
b)您的内容编码"标题字段可能不正确。它表示您正在发送两个 deflate和gzip编码的数据。