Requesting JSON information from API. Corona

元气小坏坏 提交于 2019-11-28 10:56:49

问题


I'm trying to make an app where I will gather information from a json api http://pool-x.eu/api, and print information easly bo choosing parameter.

What is the easiest way to print each of the informations?

Was thinking something in the way of making the information a string, and then request each of the parameters that way, but I don't know if that's the way to do it.


回答1:


here's a sample code to decode the json data i just happen to make a json text file out if the link you gave and decode it hope it helps

local json = require "json"
local txt
local path = system.pathForFile( "json.txt", system.ResourceDirectory )

local file = io.open( path, "r" )
for line in file:lines() do
txt = line
end
print(txt)
local t = json.decode( txt )
print(t["pool_name"])
print(t["hashrate"])
print(t["workers"])
print(t["share_this_round"])
print(t["last_block"])
print(t["network_hashrate"])


来源:https://stackoverflow.com/questions/16724207/requesting-json-information-from-api-corona

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!