本文介绍了从API请求JSON信息.电晕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个应用程序,在其中我将从json api中收集信息. http://pool- x.eu/api ,并通过选择参数轻松打印信息.

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.

推荐答案

下面是一个示例代码,用于解码json数据,如果您提供的链接希望对json文本文件进行解码并希望对您有用,那么我恰好制作了一个json文本文件

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"])

这篇关于从API请求JSON信息.电晕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:01