json - 无法在 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
推荐阅读
- wordpress - 如何将短链接网址重定向到特定页面?
- excel - 如何将正确和错误答案的数量放入excel图表的单列中
- python - 如何使用 Bokeh 获取 pandas 时间序列数据框的条形图?
- javascript - html表响应未显示在按钮单击jquery函数的MVC视图中
- mysql - 即使插入了列,“WHERE”子句中的 SQL 未知列
- xml - 在仪表板中过滤 2 个样本源(FocusVision Decipher)
- azure - MS Teams 中的 Azure 聊天机器人
- c++ - 如何用 range-v3 的范围填充 std::array?
- javascript - 如何创建“收藏此页”按钮?
- redirect - 无法重定向到新链接