Skip to content

Commit 1482cfe

Browse files
committed
fix: 切片为空时过滤结果:{}->[]
1 parent d9df98e commit 1482cfe

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

filter/parser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,13 @@ func parserSliceOrArray(typeOf reflect.Type, valueOf reflect.Value, t *fieldNode
305305
return
306306
}
307307
}
308-
308+
t.IsSlice = true
309309
l := valueOf.Len()
310310
if l == 0 {
311311
t.Val = emptySlice
312312
return
313313
}
314314

315-
t.IsSlice = true
316315
for i := 0; i < l; i++ {
317316
sliceIsNil := false
318317
node := &fieldNodeTree{

test/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"github.com/liu-cn/json-filter/filter"
7-
"time"
87
)
98

109
func mustJson(v interface{}) string {
@@ -88,10 +87,13 @@ func goSelect() {
8887
}
8988

9089
func main() {
91-
90+
//var testSlice = []int{}
91+
var testSlice = []Article{}
92+
j, _ := json.Marshal(filter.Select("t", testSlice))
93+
fmt.Println(string(j))
9294
//goOmit()
93-
goSelect()
94-
time.Sleep(time.Second * 10)
95+
//goSelect()
96+
//time.Sleep(time.Second * 10)
9597
//var bb = []byte(`{"a":"1"}`)
9698
//u := Us{
9799
// BB: [3]byte{1, 2, 4},

0 commit comments

Comments
 (0)