package main import ( "io/ioutil" "log" "regexp" "testing" "github.com/tidwall/gjson" ) func TestTaskEx_Execute(t *testing.T) { rule := regexp.MustCompile(`\\"label\\"\:\\"广告\\"|\\"label_style\\"\:3`) data, err := ioutil.ReadFile("../s.json") if err != nil { panic(err) } log.Println(rule.MatchString(string(data))) log.Println(gjson.Valid(string(data))) P := gjson.Parse(string(data)) gADDate := P.Get(`data.ordered_info.#.ad_data`) log.Println(gADDate.Exists(), gADDate.IsArray()) if !(gADDate.Exists() && gADDate.IsArray()) { t.Error("path is error") } for _, result := range gADDate.Array() { log.Println(gjson.Valid(result.Raw)) } }