简体   繁体   English

我的表格的Python错误

[英]Python error for my table

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"]

On the line where itm = t["Items"][i]["AssetId"] is where I get the error? 在哪里itm = t["Items"][i]["AssetId"]是我得到错误的地方? I'm not sure why since I'm fairly new to using python. 我不知道为什么,因为我是使用python的新手。

The error is 错误是

list index out of range 列表索引超出范围

To avoid index out of range error you can follow this method: 为了避免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)

Note: Your existing json structure is invalid, you need to load it first with json.loads() and before that validate your json structure at jsonlint 注意:您现有的json结构无效,您需要先使用json.loads()加载它,然后在jsonlint上验证您的json结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM