From c2bcab795d09b02ed9b5be7efc4d4e243a9b5d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BE=B7=E6=BB=A1?= Date: Fri, 12 Mar 2021 13:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json/build.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/json/build.go b/json/build.go index 65c4ae3..2c4c709 100644 --- a/json/build.go +++ b/json/build.go @@ -217,11 +217,12 @@ func (dj *DynamicJSON) extraSliceIndex(key string) (bool, int) { // slice 至少是 [1] 格式 return false, 0 } - // 不用正则,直接字符串处理 - strByte := []byte(key) - if string(strByte[0:1]) != "[" || string(strByte[len(strByte)-1:]) != "]" { + + if !strings.HasPrefix(key, "[") || !strings.HasSuffix(key, "]") { return false, 0 } + // 不用正则,直接字符串处理 + strByte := []byte(key) index, err := strconv.Atoi(string(strByte[1 : len(strByte)-1])) if nil != err { return false, 0