package tools import ( "github.com/tidwall/gjson" "log" "testing" ) func TestJsonDecode(t *testing.T) { str := `{"errcode":0,"errmsg":"ok","customer_list":[{"external_userid":"wmPowHDwAAnmJ72xZNnZrNz578Aqx6Kg","nickname":"唯一客服技术开发-老狼","avatar":"http://wx.qlogo.cn/mmhead/ajNVdqHZLLB6F5kbdicdPiccIbhLLnZ3q4ic8xibBwrNBG0Eupo31x427g/0","gender":1}],"invalid_external_userid":[]}` var json map[string]interface{} err := JsonDecode(str, &json) log.Println(json, err) log.Println(json["customer_list"].([]interface{})[0].(map[string]interface{})["nickname"]) visitorName := gjson.Get(str, "customer_list.0.nickname").String() avator := gjson.Get(str, "customer_list.0.avatar").String() log.Println(visitorName, avator) }