mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
如果调用internal 下的json.Marshal时 参数如果是gerror.Error 并且 字段中带有符号" 会导致序列化失败 原因是原gerror.Error 的MarshalJson方法只对字符串做了简单的处理 如果err.Error 返回的字符串中有符号" 这个符号会在序列化的时候被认为是字符串的终止导致序列化失败 <img width="854" height="186" alt="image" src="https://github.com/user-attachments/assets/9a1e6d72-943f-41ad-a487-8a3c0f28f9f0" /> --------- Co-authored-by: hailaz <739476267@qq.com>
18 lines
511 B
Go
18 lines
511 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gerror
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
|
// Note that do not use pointer as its receiver here.
|
|
func (err Error) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(err.Error())
|
|
}
|