t={"Items":[{"AssetId":1609391663,"Name":"Green Checkered Lamp shade","AbsoluteUrl":"https://www.roblox.com/catalog/1609391663/Green-Checkered-Lamp-shade","Price":20,"BestPrice":null,"Remaining":null,"HasSecondaryInfo":false,"NoPriceText":null,"IsFree":false,"Creator":null,"AssetRestrictionIcon":{"TooltipText":null,"CssTag":null,"LoadAssetRestrictionIconCss":true,"HasTooltip":false},"AssetStatusIcon":{"CssTag":"sale","DisplayText":"New","ShowTimerIcon":true},"Thumbnail":{"Final":true,"Url":"https://t0.rbxcdn.com/9fbc2414f0f615cd69ac5b8438861eaa","RetryUrl":"","IsApproved":true}},{"AssetId":1587175771,"Name":"Overseer Wings of Terror","AbsoluteUrl":"https://www.roblox.com/catalog/1587175771/Overseer-Wings-of-Terror","Price":20000,"BestPrice":null,"Remaining":275,"HasSecondaryInfo":true,"NoPriceText":null,"IsFree":false,"Creator":null,"AssetRestrictionIcon":{"TooltipText":"Serialized limited release, resellable.","CssTag":"limited-unique","LoadAssetRestrictionIconCss":true,"HasTooltip":false},"AssetStatusIcon":null,"Thumbnail":{"Final":true,"Url":"https://t7.rbxcdn.com/f6de30365dbad45c10685044d46bdffa","RetryUrl":"","IsApproved":true}},
for i in range(5):
itm = t["Items"][i]["AssetId"]
if not ListedItems.get(itm):
if t["Items"][i]["AssetStatusIcon"]:
ListedItems[t["Items"][i]["AssetId"]] = True
msg = "@everyone\n\n-----New Item!-----\n" + t["Items"][i]["AbsoluteUrl"]
在我itm = t["Items"][i]["AssetId"]
出现错误的行上?
我不确定为什么因为我很擅长使用python。
错误是
列出索引超出范围
答案 0 :(得分:0)
为避免index out of range
错误,您可以按照以下方法操作:
for itm in items:
icon = itm.get('AssetStatusIcon', None)
if icon:
msg = "@everyone\n\n-----New Item!-----\n" + itm.get('AbsoluteUrl')
print(msg)
注意:您现有的json结构无效,您需要先使用json.loads()
加载它,然后再在jsonlint验证您的json结构