lua解析json
发布日期:2021-06-30 19:39:28 浏览次数:2 分类:技术文章

本文共 1366 字,大约阅读时间需要 4 分钟。

转载注明出处:

需要解析的json数据gui-config.json

{      "configs": [{          "server": "JP3.ISS.TF",          "server_port": 443,          "password": "58603228",          "method": "aes-256-cfb",          "remarks": ""      },      {          "server": "US1.ISS.TF",          "server_port": 443,          "password": "37382928",          "method": "aes-256-cfb",          "remarks": ""      },      {          "server": "HK2.ISS.TF",          "server_port": 8989,          "password": "59434206",          "method": "aes-256-cfb",          "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  

 

输出:

 

转载地址:https://linxinfa.blog.csdn.net/article/details/76557700 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:光猫连接无线路由器
下一篇:微信开放平台android接入笔记(unity3d)

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年05月01日 17时49分28秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章