Skip to content

Instantly share code, notes, and snippets.

@n0bisuke
Last active December 18, 2015 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0bisuke/5706215 to your computer and use it in GitHub Desktop.
Save n0bisuke/5706215 to your computer and use it in GitHub Desktop.
coronasdkでhttp通信(GET)をしてJSONを取得してパースする
--[[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