requests返回.text类型形似dict,索引后报错“TypeError:string indices must be integers”

requests请求后,response.text打印后是一个形似dict的东西,打印其类型,发现为Unicode类型。

此时若直接将其当做dict来索引,会报错 TypeError:string indices must be integers

解决此问题,需要先将Unicode类型的数据转换成 string,在用json.load()将其转换成dict。

result = response.text.encode("utf8")

result = json.loads(result)

原文地址:https://www.cnblogs.com/ylqm/p/9629251.html