懒人精灵 之 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
相关推荐
FFZero18 小时前
【C++/Lua联合开发】 (三) C++调用Lua
c++·junit·lua
njsgcs10 小时前
json转excel python pd
python·json·excel·pd
代码搬运媛20 小时前
【架构相关】tsconfig.json 与 tsconfig.node.json、tsconfig.app.json 的关系和作用
node.js·json
疯狂吧小飞牛1 天前
Lua C API 中的 lua_rawseti 与 lua_rawgeti 介绍
c语言·开发语言·lua
半夏知半秋1 天前
lua对象池管理工具剖析
服务器·开发语言·后端·学习·lua
爬山算法1 天前
Redis(63)Redis的Lua脚本如何使用?
redis·junit·lua
疯狂吧小飞牛2 天前
Lua 中的 __index、__newindex、rawget 与 rawset 介绍
开发语言·junit·lua
疯狂吧小飞牛2 天前
Lua C API 中的注册表介绍
java·c语言·lua
安冬的码畜日常2 天前
【JUnit实战3_02】第二章:探索 JUnit 的核心功能(一)
数据库·junit·sqlserver
爬山算法2 天前
Redis(64)Redis的Lua脚本有哪些常见场景?
数据库·redis·lua