@@ -185,7 +185,7 @@ func searchKeys(data []byte, keys ...string) int {
185185 var valueOffset int
186186
187187 ArrayEach (data [i :], func (value []byte , dataType ValueType , offset int , err error ) {
188- if ( curIdx == aIdx ) {
188+ if curIdx == aIdx {
189189 valueFound = value
190190 valueOffset = offset
191191 }
@@ -344,7 +344,7 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
344344 continue
345345 }
346346
347- aIdx , _ := strconv .Atoi (p [level ][1 : len (p [level ]) - 1 ])
347+ aIdx , _ := strconv .Atoi (p [level ][1 : len (p [level ])- 1 ])
348348 arrIdxFlags |= bitwiseFlags [aIdx + 1 ]
349349 pIdxFlags |= bitwiseFlags [pi + 1 ]
350350 }
@@ -354,10 +354,10 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
354354
355355 var curIdx int
356356 arrOff , _ := ArrayEach (data [i :], func (value []byte , dataType ValueType , offset int , err error ) {
357- if ( arrIdxFlags & bitwiseFlags [curIdx + 1 ] != 0 ) {
357+ if arrIdxFlags & bitwiseFlags [curIdx + 1 ] != 0 {
358358 for pi , p := range paths {
359359 if pIdxFlags & bitwiseFlags [pi + 1 ] != 0 {
360- aIdx , _ := strconv .Atoi (p [level - 1 ][1 : len (p [level - 1 ]) - 1 ])
360+ aIdx , _ := strconv .Atoi (p [level - 1 ][1 : len (p [level - 1 ])- 1 ])
361361
362362 if curIdx == aIdx {
363363 of := searchKeys (value , p [level :]... )
@@ -571,6 +571,17 @@ func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int
571571 offset ++
572572 }
573573
574+ nO := nextToken (data [offset :])
575+ if nO == - 1 {
576+ return offset , MalformedJsonError
577+ }
578+
579+ offset += nO
580+
581+ if data [offset ] == ']' {
582+ return offset , nil
583+ }
584+
574585 for true {
575586 v , t , o , e := Get (data [offset :])
576587
@@ -583,7 +594,7 @@ func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int
583594 }
584595
585596 if t != NotExist {
586- cb (v , t , offset + o - len (v ), e )
597+ cb (v , t , offset + o - len (v ), e )
587598 }
588599
589600 if e != nil {
0 commit comments