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? I'm not sure why since I'm fairly new to using python.
The error is
list index out of range
To avoid index out of range
error you can follow this method:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.