11package main
22
33import (
4+ "encoding/json"
45 "fmt"
56 "github.com/liu-cn/json-filter/filter"
67)
@@ -15,7 +16,26 @@ type Map struct {
1516 MPP * * map [string ]* * string `json:"mpp,select(test)"`
1617}
1718
19+ type IntMap struct {
20+ IntMaps map [int ]string `json:"int_maps,select(IntMaps)"`
21+ UintMap map [uint ]string `json:"uint_map,select(UintMap)"`
22+ StringMap map [string ]string `json:"string_map,select(StringMap)"`
23+ //BoolMap map[bool]string `json:"bool_map,select(BoolMap)"`
24+ //FloatMap map[float32]string `json:"float_map,select(FloatMap)"`
25+ //ComplexMap map[complex64]string `json:"complex_map,select(ComplexMap)"`
26+ }
27+
1828func TestMap () {
29+ //a := 1
30+ //m := map[interface{}]string{
31+ // a: "ooo",
32+ // "b": "bbb",
33+ //}
34+ //marshal, err := json.Marshal(m)
35+ //if err != nil {
36+ // panic(err)
37+ //}
38+ //fmt.Println(string(marshal))
1939
2040 str := "c++从研发到脱发"
2141 ptr := & str
@@ -28,4 +48,23 @@ func TestMap() {
2848
2949 fmt .Println ("omit:" , filter .Select ("test" , Map {M : maps , T : maps , MP : mp , MPP : mpp }))
3050 //{"m":{"test":"c++从研发到脱发"},"mp":{"test":"c++从研发到脱发"},"mpp":{"test":"c++从研发到脱发"}}
51+
52+ mmm := IntMap {
53+ IntMaps : map [int ]string {- 1 : "一" , 1 : "二" },
54+ UintMap : map [uint ]string {1 : "一" , 2 : "二" },
55+ StringMap : map [string ]string {"s" : "s" },
56+ //FloatMap: map[float32]string{1.12: "一.12", 2.67657: "二.67657"},
57+ //BoolMap: map[bool]string{true: "true", false: "false"},
58+ //ComplexMap: map[complex64]string{complex64(1): "1", complex64(2): "2"},
59+ }
60+ marshal , err := json .Marshal (mmm )
61+ if err != nil {
62+ panic (err )
63+ }
64+ fmt .Println (string (marshal ))
65+
66+ fmt .Println (filter .Select ("IntMaps" , mmm ))
67+ fmt .Println (filter .Select ("UintMap" , mmm ))
68+ fmt .Println (filter .Select ("StringMap" , mmm ))
69+
3170}
0 commit comments