-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtttest.go
53 lines (46 loc) · 959 Bytes
/
tttest.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
/*
@Time : 2020/5/20 19:29
@Author : ZhaoJunfeng
@File : test
*/
package main
import (
"bytes"
"encoding/json"
"fmt"
jsoniter "github.com/json-iterator/go"
jsoniter_extra "github.com/json-iterator/go/extra"
)
type Te struct {
Tids []int `json:"cids"`
Id int `json:"id"`
}
func init() {
// json兼容性扩展
jsoniter_extra.RegisterFuzzyDecoders()
}
func main() {
var test Te
test = Te{
Tids:[]int{12345678,321},
Id:12345678,
}
a,_:=json.Marshal(test)
d := json.NewDecoder(bytes.NewReader(a))
d.UseNumber()
var b map[string]interface{}
d.Decode(&b)
fmt.Printf("Decode b:%+v \n",b)
fmt.Printf("Decode b.cids:%+v \n",b["cids"])
m:=b["cids"]
fmt.Printf("Decode b.cids :%+v \n",m)
n := b["id"].(json.Number)
fmt.Println(n.Float64())
fmt.Println(n.Int64())
fmt.Println(n.String())
//json.Unmarshal
json.Unmarshal(a,&b)
fmt.Printf("Unmarshal b:%+v\n",b)
jsoniter.Unmarshal(a,&b)
fmt.Printf("jsoniter.Unmarshal b:%+v\n",b)
}