我试图从一个数组中获取多个项目,但它会返回一个错误,但是如果我只得到一个则没有。 我的代码:
stockjson = json.loads(stockinfo.text)
test1 = stockjson['variation_list'][0]['test1']
print(test1)
Stockinfo:
{"id":"TestID","availability_status":"NOT_AVAILABLE","variation_list":[{"sku":"TEST1","availability":0,"availability_status":"NOT_AVAILABLE","test1":"test1"},[{"sku":"TEST2","availability":0,"availability_status":"NOT_AVAILABLE","test1":"test2"},
我想得到每个test1的结果,但如果我从代码中取出[0],我得到:
test1 = stockjson['variation_list']['test1']
TypeError: list indices must be integers or slices, not str
我也希望找到每个部分的SKU和test1(不知道该怎么称呼它),感谢您提供的任何帮助