我的选项卡出现Python错误

2024-09-28 01:26:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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还比较陌生

错误是

list index out of range


Tags: ofnamehttpscomfalsetrueitemsgreen
1条回答
网友
1楼 · 发布于 2024-09-28 01:26:25

要避免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结构

相关问题 更多 >

    热门问题