-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
130 lines (124 loc) · 2.66 KB
/
json.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"encoding/json"
"fmt"
)
// the following json is provided by @valorad/inventory
var invItems = []byte(`[
{
"id": "xmarkthespot",
"holder": "actor-dragonborn",
"item": "item-stimpack",
"refDetails": [
{
"refID": "wearewaitingfortes6",
"owner": "actor-dragonborn",
"num": 1,
"item": "item-stimpack"
},
{
"refID": "fallout76pugai",
"owner": "actor-dragonborn",
"num": 2,
"item": "item-stimpack"
},
{
"refID": "sc2terrible",
"owner": "actor-dragonborn",
"num": 3,
"item": "item-stimpack"
}
],
"base": {
"dbname": "item-stimpack",
"name": "Stimpack",
"description": "",
"value": 152,
"weight": 0.1,
"category": "comsumables",
"detail": {
"type": "type-potion",
"typeName": "Potions",
"effectsI18n": [
"Heal"
]
}
}
},
{
"id": "whosyourdaddy",
"holder": "actor-dragonborn",
"item": "item-iron_helmet",
"refDetails": [
{
"refID": "gpangDontknow3",
"owner": "actor-dragonborn",
"num": 4,
"item": "item-iron_helmet"
}
],
"base": {
"dbname": "item-iron_helmet",
"name": "Iron Helmet",
"description": "",
"value": 75,
"weight": 2,
"category": "gears",
"detail": {
"rating": 10,
"type": "type-heavyarmor",
"typeName": "Heavy Armor",
"equipI18n": [
{
"name": "head",
"equip": "equip-head"
}
],
"effectsI18n": []
}
}
},
{
"id": "robinhood",
"holder": "actor-dragonborn",
"item": "item-darkbro_tenant",
"refDetails": [
{
"refID": "jadoretesassiettes",
"owner": "actor-dragonborn",
"num": 5,
"item": "item-iron_helmet"
}
],
"base": {
"dbname": "item-darkbro_tenant",
"name": "Dark brother tenant",
"description": "The divine tenant of Dark brothers",
"value": 5,
"weight": 1,
"category": "books",
"detail": {
"content": "content-darkbro_tenant",
"contentDetail": "Dark-bro rules: 1. No black sacrament on kittens. 2. No D.."
}
}
}
]`)
// InvItemSlice {invItem[]}
type InvItemSlice struct {
Items []InvItem
}
// InvItem {invItem}
type InvItem struct {
Id string
Item string
}
func unMarshalToStruct() InvItemSlice {
var invItemslice InvItemSlice
err := json.Unmarshal(invItems, &invItemslice.Items)
fmt.Println(err)
return invItemslice
}
func mainjson() {
fmt.Println(unMarshalToStruct())
}