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