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

Merge pull request #598 from wdvxdr1123/music_share

fix null json
This commit is contained in:
Mrs4s 2021-01-27 17:58:21 +08:00 committed by GitHub
commit a9619b25bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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)