I have a script that looks through a JSON structure. Every now and again, a particular key is missing. When these instances occur, I need the script to continue rather than stop. Here is my code:
for i = 1:length(marketCatalogueResult)
marketResults = getMarketOffers(currentCatalogue[i,1])
push!(lastTradeP1, marketResults[1]["runners"][1]["lastPriceTraded"])
push!(lastTradeP2, marketResults[1]["runners"][2]["lastPriceTraded"])
end
end
The error I sometimes get is:
KeyError: key "lastPriceTraded" not found
How can I amend my code to handle the stated error?
9 posts - 5 participants