LUA解析json小demo
2017-03-25 00:00
281 查看
需要修改的json数据gui-config.json
LUA解析代码:
输出:
{ "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://static.oschina.net/uploads/img/201703/25104205_tIng.jpg)
相关文章推荐
- json解析到listview(爱帮公交demo)
- httpclient demo 3.1 4.2不同版本的API实现 解析JSON
- Android实战--解析稍复杂JSON数据DEMO
- Android开发-Volley-解析Json使用方法-完整Demo-AndroidStudio
- cocos2d-x lua 3.6 解析json
- 简单解析json数据demo
- android中json解析的两个工具:Gson和Jackson的使用小demo
- quick cocos2d-x lua解析json文件
- Gson,Fast-Json解析 Demo
- lua解析json
- Json数据解析代码demo
- Swift学习6——解析json天气信息Demo
- Win(Phone)10开发第(3)弹,简单的Demo程序网络请求json解析列表显示
- 使用GSON解析复杂的JSON数据(有DEMO)
- json解析到listview(爱帮公交demo)
- Cocos2d-x教程(22)-lua中的json解析
- Cocos2dx&Lua - UI显示优化之如何解决解析大量json文件
- [安卓开发]快递查询demo|Json解析|条形码扫描|物流布局|历史记录
- json解析,异步下载(listview仅滑动时加载)Demo总结
- Android开发-Volley-解析Json使用方法-完整Demo-AndroidStudio