Gabs是一个用来处理动态或未知jso结构的golag库。通过包装jso.Marshal/jso.Umarshal的行为和map[strig]iterface{}对象,Gabs提供了更大的便利性。
解析和搜索JSON...import "github.com/Jeffail/gabs"jsoParsed, err := gabs.ParseJSON([]byte(`{ "outter":{ "ier":{ "value1":10, "value2":22 }, "alsoIer":{ "value1":20 } }}`))var value float64var ok boolvalue, ok = jsoParsed.Path("outter.ier.value1").Data().(float64)// value == 10.0, ok == truevalue, ok = jsoParsed.Search("outter", "ier", "value1").Data().(float64)// value == 10.0, ok == truevalue, ok = jsoParsed.Path("does.ot.exist").Data().(float64)// value == 0.0, ok == falseexists := jsoParsed.Exists("outter", "ier", "value1")// exists == trueexists := jsoParsed.Exists("does", "ot", "exist")// exists == falseexists := jsoParsed.ExistsP("does.ot.exist")// exists == false...点击空白处退出提示
评论