Last active
December 18, 2015 01:48
-
-
Save n0bisuke/5706215 to your computer and use it in GitHub Desktop.
coronasdkでhttp通信(GET)をしてJSONを取得してパースする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[CoronaSDKでGETの実装+Jsonのパース]] | |
--表示用のテキスト | |
local myGet = display.newText("[レスポンス]\n", 70, 10, 200,500, native.systemFont, 20) | |
local json = require "json" | |
local function networkListener( event ) | |
if ( event.isError ) then --通信が失敗 | |
myGet.text = "Network error!" | |
else --通信が成功 | |
local t = json.decode( event.response ) | |
for key,value in pairs(t.response) do | |
--questionだけ取り出す | |
myGet.text = myGet.text .. value.MoridaiQuestion.question .. "\n\n" | |
end | |
end | |
end | |
network.request("http://n0.x0.to/pbl/sample/test.json", "GET", networkListener) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment