Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 字符串索引必须是整数_Python - Fatal编程技术网

Python 字符串索引必须是整数

Python 字符串索引必须是整数,python,Python,我有一个json数据 需要获取所有项目的名称 r = requests.get('https://steamcommunity.com/id/RednelssGames/inventory/json/730/2') if r.json()['success'] == True: for rows in r.json()['rgDescriptions']: print(rows['market_hash_name']) 从您提供的链接获取错误字符串索引必须是整数:

我有一个json数据 需要获取所有项目的名称

r = requests.get('https://steamcommunity.com/id/RednelssGames/inventory/json/730/2')
if r.json()['success'] == True:
     for rows in r.json()['rgDescriptions']:
         print(rows['market_hash_name'])

从您提供的链接获取错误字符串索引必须是整数:

"rgDescriptions":{"4291220570_302028390":
rgDescriptions
不返回数组,而是返回一个对象(在本例中是字典)(请注意开头的大括号(
{
)而不是常规的方括号(
[

通过对r.json()['rgDescriptions']中的行使用
可以迭代字典的键。字典的第一个键似乎是
“4291220570_302028390”
,这是一个字符串


因此,当您执行
打印(rows['market\u hash\u name'])
时,您试图访问
rows
对象的
'market\u hash\u name'
索引,但
rows
实际上是一个字符串,因此它不起作用。

更改for循环如下:

对于r.json()['rgDescriptions'].values()中的行:
打印(行['market\u hash\u name'])

通过像以前一样迭代字典,可以得到键,而不是值(行)。如果要迭代值,必须迭代
dict.values()的返回值

您没有为其他人提供足够的信息来执行此代码。@ScottHunter他提供了!这肯定不是
cookies
=?
=?如何修复此问题?:c