diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/httpclient.go b/httpclient.go index f444bb0..a8e265e 100644 --- a/httpclient.go +++ b/httpclient.go @@ -156,6 +156,17 @@ func (this *Response) ToString() (string, error) { return string(bytes), nil } +func (this *Response) ToJson(v interface{}) error { + bytes, err := this.ReadAll() + if err != nil { + return err + } + if err = json.Unmarshal(bytes, v); err != nil { + return err + } + return nil +} + // Prepare a request. func prepareRequest(method string, url_ string, headers map[string]string, body io.Reader, options map[int]interface{}) (*http.Request, error) {