-
Notifications
You must be signed in to change notification settings - Fork 3
/
json1.go
54 lines (43 loc) · 1.13 KB
/
json1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package jsonKit
func MarshalWithAPI(api API, v interface{}) ([]byte, error) {
if api == nil {
api = defaultAPI
}
return api.Marshal(v)
}
// MarshalIndentWithAPI
/*
@param indent 为了兼容性,用" "(4个空格)替代"\t"
*/
func MarshalIndentWithAPI(api API, v interface{}, prefix, indent string) ([]byte, error) {
if api == nil {
api = defaultAPI
}
return api.MarshalIndent(v, prefix, indent)
}
func MarshalToStringWithAPI(api API, v interface{}) (string, error) {
if api == nil {
api = defaultAPI
}
return api.MarshalToString(v)
}
// MarshalIndentToStringWithAPI
/*
@param indent 为了兼容性,用" "(4个空格)替代"\t"
*/
func MarshalIndentToStringWithAPI(api API, v interface{}, prefix, indent string) (string, error) {
data, err := MarshalIndentWithAPI(api, v, prefix, indent)
return string(data), err
}
func UnmarshalWithAPI(api API, data []byte, v interface{}) error {
if api == nil {
api = defaultAPI
}
return api.Unmarshal(data, v)
}
func UnmarshalFromStringWithAPI(api API, str string, v interface{}) error {
if api == nil {
api = defaultAPI
}
return api.UnmarshalFromString(str, v)
}