无法解析 ROBLOX Lua 中的 JSON



我正在制作一个模块脚本,如果调用它的播放器是JSON对象中的字符串,则运行另一个模块。

我得到这个错误:

Can't parse JSON
-- Stack Begin
-- Script 'Model.MainModule', Line 8 - function load
-- Stack End

代码:

local module = {}
function module.load(plr)
local HttpService = game:GetService("HttpService")

local decoded = HttpService:JSONDecode('{ players: ["HiroTDM999", "mrhotmadm"] }')
for i, v in pairs(decoded.players) do
if v == plr.Name then
require(6380716368).load() -- runs another module (no json in it)
end
end
end
return module

JSON是无效的,你需要把玩家用双引号括起来。

local module = {}
function module.load(plr)
local HttpService = game:GetService("HttpService")

local decoded = HttpService:JSONDecode('{ "players": ["HiroTDM999", "mrhotmadm"] }')
for i, v in pairs(decoded.players) do
if v == plr.Name then
require(6380716368).load() -- runs another module (no json in it)
end
end
end
return module

最新更新