LUA解析json小demo

LUA解析json小demo,第1张

概述需要修改的json数据gui-config.json { "configs": [{ "server": "JP3.ISS.TF", "server_port": 443, "password": "58603228", "method": "aes-256-cfb", "remarks": "" }, { "server": "US1.ISS.TF", "ser

需要修改的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;endfunction fileWrite()	local file = io.open("gui-config.Json","w");	file:close();endlocal 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

输出:

总结

以上是内存溢出为你收集整理的LUA解析json小demo全部内容,希望文章能够帮你解决LUA解析json小demo所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1243574.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存