tipStr = string.format("本次回收【<font color=\"#FFF000\">%d</font>】件装备,获得绑定元宝[<font color=\"#FFF000\">%d</font>]", Takecount, Takemoney) sendmsg(actor,1,'{"Msg":"<font color=\"#ff0000\">系统提示:</font>'..tipStr..',"Type":9}') 为啥发送不了
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-06-13 15:08:37 |
👁️ 阅读: 3
我是lua后端老师!
小仙,你这段代码发送不了是因为JSON格式有问题!让我帮你分析一下:
```lua
tipStr = string.format("本次回收【<font color=\"#FFF000\">%d</font>】件装备,获得绑定元宝[<font color=\"#FFF000\">%d</font>]", Takecount, Takemoney)
sendmsg(actor,1,'{"Msg":"<font color=\"#ff0000\">系统提示:</font>'..tipStr..',"Type":9}')
```
**问题分析:**
1. **JSON格式错误**:你的JSON字符串中,`tipStr`后面直接跟了逗号和`"Type":9}`,但是`tipStr`本身没有用双引号包裹
2. **缺少双引号闭合**:`"Msg":"<font color=\"#ff0000\">系统提示:</font>`后面拼接`tipStr`时,应该用双引号包裹整个字符串
**正确写法应该是:**
```lua
tipStr = string.format("本次回收【<font color=\"#FFF000\">%d</font>】件装备,获得绑定元宝[<font color=\"#FFF000\">%d</font>]", Takecount, Takemoney)
local msgJson = '{"Msg":"<font color=\"#ff0000\">系统提示:</font>'..tipStr..'","Type":9}'
sendmsg(actor, 1, msgJson)
```
**关键修改点:**
1. 在`tipStr`后面加上了`"`来闭合Msg字段的双引号
2. 整个JSON字符串格式为:`{"Msg":"完整消息内容","Type":9}`
**更简洁的写法:**
```lua
local tipStr = string.format("本次回收【<font color=\"#FFF000\">%d</font>】件装备,获得绑定元宝[<font color=\"#FFF000\">%d</font>]", Takecount, Takemoney)
local msgJson = string.format('{"Msg":"<font color="#ff0000">系统提示:</font>%s","Type":9}', tipStr)
sendmsg(actor, 1, msgJson)
```
这样就能正确发送系统提示消息了!JSON格式一定要严格,每个字段都要用双引号正确包裹。
← 返回问答库