Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JsonDecode ¶
JsonDecode 解析JSON数据,同时在解析失败时保留原始数据 参数:
- rd: 数据源,实现io.Reader接口
- dst: 目标结构体指针,解析后的数据将存储在此
返回值:
- error: 解析成功返回nil,失败返回JsonDecodeError包含原始数据
示例:
var user User
err := JsonDecode(response.Body, &user)
if err != nil {
var jsonErr *JsonDecodeError
if errors.As(err, &jsonErr) {
log.Printf("Failed to parse: %s, raw data: %s", err, jsonErr.Raw.String())
}
}
func ReadErrRaw ¶
Types ¶
type JsonDecodeError ¶
JsonDecodeError json解析错误 包含原始数据
func (*JsonDecodeError) Error ¶
func (e *JsonDecodeError) Error() string
func (*JsonDecodeError) Unwrap ¶
func (e *JsonDecodeError) Unwrap() error
Unwrap 返回被包装的原始错误,用于errors.Is和errors.As
Click to show internal directories.
Click to hide internal directories.