#sudo aptitude install lua-cjson
1)实现test.json
-
{
-
"str":"hello world",
-
"configs":[{
-
"user":"ubuntu",
-
"password":"123456",
-
"ip":"....."
-
},
-
{
-
"user":"ubuntu1",
-
"password":"....",
-
"ip":"testip"
-
}
-
]
-
}
2)实现test.lua
-
function FileRead()
-
local file = io.open("test.json","r")
-
local json = file:read("*a");
-
file:close()
-
return json
-
end
-
local cjson = require "cjson"
-
local file = FileRead()
-
local json = cjson.decode(file)
-
-
for i,w in ipairs(json.configs) do
-
print("user:"..w.user)
-
print("password:"..w.password)
-
end
-
print("str:"..json.str)
3)运行
#lua5.1 test.lua
阅读(2990) | 评论(0) | 转发(0) |