1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 03:53:50 +08:00

fix null json

This commit is contained in:
wdvxdr 2021-01-27 16:08:59 +08:00
parent 18a839b699
commit 69cda4e029
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6

View File

@ -25,12 +25,18 @@ func (m MSG) Get(s string) MSG {
}
return MSG{"__str__": v} // 用这个名字应该没问题吧
}
return MSG{}
return nil // 不存在为空
}
//String 将消息Map转化为String。若Map存在key "__str__",则返回此key对应的值,否则将输出整张消息Map对应的JSON字符串
func (m MSG) String() string {
if m == nil {
return "" // 空 JSON
}
if str, ok := m["__str__"]; ok {
if str == nil {
return "" // 空 JSON
}
return fmt.Sprint(str)
}
str, _ := json.MarshalToString(m)