June 16, 2016 15:38:25read: 2575 Tags: golang json array more Personal Category: Golang
Func Main () {a: = []Byte' {"Parents": ["AAAAA", "BBBBBBB"]} ') b: = []Byte' {"Parents": ["Gomez", "Moticia"]} ')var arr []interface{} js, _: = Simplejson. Newjson (a) nodes, _: = js. Map () P: = Nodes[ "parents"] D: = P. ([]interface{}) for _, V: = range d {arr = append (arr, v)} js, _ = Simplejson. Newjson (b) nodes, _ = js. Map () p = Nodes[ "parents"] D = P. ([]interface{}) for _, V: = range d {arr = append (arr, v)} res: = Span class= "hljs-built_in" >make (map[string]interface{}") Res[ "parents"] = Arr C, _: = json. Marshal (res) FMT. Println (string (c))}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
Results:
{"Parents": ["AAAAA", "bbbbbbb", "Gomez", "Moticia"]}
Correspondingly, if the array is inside the interface type also applies.
Golang JSON Array Stitching