懒人精灵 之 Lua 捕获 json解析异常 ,造成的脚本停止.

Time: 2024年2月8日20:21:17 by:MemoryErHero

1 异常代码

lua 复制代码
Expected value but found T_END at character 1

2 异常代码

lua 复制代码
Expected value but found T_OBJ_END at character 22

3 处理方案 - 正确 json 示范

lua 复制代码
while true do
	--Expected value but found T_END at character 1
    --Expected value but found T_OBJ_END at character 22
	local str = '{"success":0,"code":[]}'
	local err,tbl = pcall(function(str)return jsonLib.decode(str)end,str)
	print(err)
	print(tbl)
    sleep(1000)
end

4 处理方案 - 错误 json 示范

lua 复制代码
while true do
	--Expected value but found T_END at character 1
    --Expected value but found T_OBJ_END at character 22
	local str = '{"success":0,"code":[}'
	local err,tbl = pcall(function(str)return jsonLib.decode(str)end,str)
	print(err)
	print(tbl)
    sleep(1000)
end
相关推荐
吴声子夜歌1 小时前
PlantUML——显示JSON数据
json
祀爱2 小时前
ControllerBase 类将对象转换为 JSON 格式并返回前端的方法
前端·json·asp.net
weelinking16 小时前
【产品】11_实现后端接口——数据在背后如何流动
java·人工智能·python·sql·oracle·json·ai编程
wapicn991 天前
API接口调试笔记:从注册到第一个数据返回,全流程详解
java·开发语言·python·lua
油炸自行车1 天前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
NiceCloud喜云2 天前
Claude Code 跑 HyperFrames 实测:本地生成 AI 视频素材全流程
java·运维·人工智能·自动化·json·音视频·飞书
kebeiovo2 天前
C++与 Lua的交互
c++·lua
逍遥德2 天前
PostgreSQL --- JSON 函数详解
数据库·sql·postgresql·json
輕華2 天前
Flask_GET请求与JSON响应实战详解
python·flask·json
NiceCloud喜云3 天前
Claude Code Routines 实战:三种触发器跑通云端自动化编码
android·运维·数据库·人工智能·自动化·json·飞书