加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

LUA解析json小demo

发布时间:2020-12-14 21:57:30 所属栏目:大数据 来源:网络整理
导读:需要修改的json数据gui-config.json {"configs": [{"server": "JP3.ISS.TF","server_port": 443,"password": "58603228","method": "aes-256-cfb","remarks": ""},{"server": "US1.ISS.TF","password": "37382928",{"server": "HK2.ISS.TF","server_port": 8

需要修改的json数据gui-config.json

{
	"configs": [{
		"server": "JP3.ISS.TF","server_port": 443,"password": "58603228","method": "aes-256-cfb","remarks": ""
	},{
		"server": "US1.ISS.TF","password": "37382928",{
		"server": "HK2.ISS.TF","server_port": 8989,"password": "59434206","remarks": ""
	}],"strategy": null,"index": 0,"global": false,"enabled": true,"shareOverLan": false,"isDefault": false,"localPort": 1080,"pacUrl": null,"uSEOnlinePac": false,"availabilityStatistics": false
}


LUA解析代码:

function FileRead()
	local file = io.open("gui-config.json","r");
	local json = file:read("*a");
	file:close();
	return json;
end

function FileWrite()
	local file = io.open("gui-config.json","w");
	file:close();
end

local cjson = require("cjson");
local file = FileRead();
local json = cjson.decode(file);
for i,w in ipairs(json.configs) do
	print("server: " .. w.password)
	print("server_port: " .. w.server_port)
	print("password: " .. w.password)
	print("method: " .. w.method .. 'n')
end

输出:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读