我是靠谱客的博主 知性自行车,这篇文章主要介绍python提取json数据索引必须是整数_Python JSON TypeError列表索引必须是整数或切片,而不是str...,现在分享给大家,希望可以做个参考。

我目前正在尝试从发布请求响应中解析一些数据,并且不断收到此错误:“ TypeError:列表索引必须是整数或切片,而不是str”

Python代码

import requests

import json

count = 0

params = {'var1':'40', 'value':'143', 'itm':'1', 'param':'1'}

req = 'https://www.api.com/api/search'

data = requests.post(req, data = params).json()

print (data['result']['results']['name'])

JSON回应

{

"result":{

"count":1,

"totalCount":1,

"offset":0,

"queryTime":232,

"results":[

{

"rating":"4.0",

"productId":{

"upc":"143",

"ItemId":"143",

"productId":"143-prd"

},

"name":"Product",

"catagory":{

"name":"",

"CataId":1

},

"images":{

"thumbnailUrl":"http://api.com/img/static/product-image-50-50.png",

"largeUrl":"http://api.com/img/static/product-image-500-500.png"

},

"price":{

"price":13,

"isRealTime":true,

"currencyUnit":"USD"

},

"location":{

"unit":[],

"detailed":[]

},

"inventory":{

"quantity":1,

"status":"In Stock",

"isRealTime":true

},

"ratings":{

"rating":"3.1875",

"ratingUrl":"http://api.com/3_1875.gif"

},

"reviews":{

"reviewCount":"2"

},

"isItem":true,

"lUrl":"/l/Product-Name"

}

],

"performance":{

"enrichment":{

}

},

"query":{

"originalQuery":"143",

"actualQuery":"143",

"suggestedQueries":[

]

},

"algo":"jarvis",

"blacklist":false,

"cluster":{

"apiserver":{

"hostname":"site.api.com",

"pluginVersion":"1.0"

},

"searchengine":{

"hostname":"srch.site.api.com"

}

}

}

}

我做了类似的代码,但这是一个get请求,一切都很好。

最后

以上就是知性自行车最近收集整理的关于python提取json数据索引必须是整数_Python JSON TypeError列表索引必须是整数或切片,而不是str...的全部内容,更多相关python提取json数据索引必须是整数_Python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部