-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_json.go
More file actions
95 lines (85 loc) · 2.35 KB
/
Copy pathload_json.go
File metadata and controls
95 lines (85 loc) · 2.35 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
)
type KeyMapItem struct {
ID string `json:"ID"`
Name string `json:"Name"`
Age uint32 `json:"Age"`
}
func loadKeyMapJson() {
fileName := "test_key_map_s.json"
data, err := ioutil.ReadFile(fileName)
if err != nil {
log.Printf("ReadFile %s open failed err:%+v", fileName, err)
return
}
var mapResult map[string]KeyMapItem
err = json.Unmarshal(data, &mapResult)
if err != nil {
log.Printf("ReadFile %s Unmarshal failed err:%+v", fileName, err)
return
}
fmt.Printf("loadKeyMapJson :%+v", mapResult)
}
type probability struct {
Ratio uint32 `json:"Ratio"`
Base uint32 `json:"Base"`
}
type KeyArrayItem struct {
ID uint32 `json:"ID"`
Ratio float32 `json:"Ratio"`
Reward []uint32 `json:"Reward"`
TaxRatio probability `json:"TaxRatio"`
}
func loadKeyArrayJson() {
fileName := "test_key_array_s.json"
data, err := ioutil.ReadFile(fileName)
if err != nil {
log.Printf("ReadFile %s open failed err:%+v", fileName, err)
return
}
var arrayResult []KeyArrayItem
err = json.Unmarshal(data, &arrayResult)
if err != nil {
log.Printf("ReadFile %s Unmarshal failed err:%+v", fileName, err)
return
}
fmt.Printf("loadKeyArrayJson :%+v", arrayResult)
}
type KeyValueItem struct {
KEY_INT uint32 `json:"KEY_INT"`
KEY_FLOAT float32 `json:"KEY_FLOAT"`
KEY_BOOL bool `json:"KEY_BOOL"`
KEY_OBJECT_ARRAY []uint32 `json:"KEY_OBJECT_ARRAY"`
KEY_OBJECT_DICT probability `json:"KEY_OBJECT_DICT"`
KEY_STRING string `json:"KEY_STRING"`
KEY_STRING_INT string `json:"KEY_STRING_INT"`
KEY_STRING_FLOAT string `json:"KEY_STRING_FLOAT"`
KEY_STRING_BOOL string `json:"KEY_STRING_BOOL"`
KEY_STRING_OBJECT_ARRAY string `json:"KEY_STRING_OBJECT_ARRAY"`
KEY_STRING_OBJECT_DICT string `json:"KEY_STRING_OBJECT_DICT"`
}
func loadKeyValueJson() {
fileName := "test_key_value_s.json"
data, err := ioutil.ReadFile(fileName)
if err != nil {
log.Printf("ReadFile %s open failed err:%+v", fileName, err)
return
}
var valueResult KeyValueItem
err = json.Unmarshal(data, &valueResult)
if err != nil {
log.Printf("ReadFile %s Unmarshal failed err:%+v", fileName, err)
return
}
fmt.Printf("loadKeyValueJson :%+v", valueResult)
}
func main() {
loadKeyMapJson()
loadKeyArrayJson()
loadKeyValueJson()
}