更新的網絡請求,我從與network.request功能的網站獲取一些JSON的東西(比特幣的價值)。但是,我希望每當用戶按下更新時,json的東西(比特幣的價值)就會更新到最新版本。這怎麼可能?在Corona SDK
local json = require("json")
btcPriceText = display.newText("price", 50,100, "Arial", 25)
local function btcValue(event)
btcValue = json.decode(event.response)
dollarbtc= btcValue[1]['rate']
end
local function update()
if(dollarbtc) then
btcPriceText.text = "BTC"..dollarbtc
end
end
network.request("https://bitpay.com/api/rates", "GET", btcValue)
Runtime:addEventListener("enterFrame", update)
這是我使用的所有代碼。
你可以發表你的場景和更新按鈕的代碼?你可以把請求放在處理程序中,但是如果沒有看到代碼,很難判斷這是否是最好的方式。 – Schollii
Schollii:我把代碼放在那裏! – user3055331