JSON returns a new Value instance with JSON decoded from response body. JSON succeeds if response contains "application/json" Content-Type header with empty or "utf-8" charset and if JSON may be decoded from response body. Example: resp := NewResponse(t, response) resp.JSON().Array().ConsistsOf
(options ...ContentOpts)
| 870 | // MediaType: "application/json", |
| 871 | // }).Array.ConsistsOf("foo", "bar") |
| 872 | func (r *Response) JSON(options ...ContentOpts) *Value { |
| 873 | opChain := r.chain.enter("JSON()") |
| 874 | defer opChain.leave() |
| 875 | |
| 876 | if opChain.failed() { |
| 877 | return newValue(opChain, nil) |
| 878 | } |
| 879 | |
| 880 | if len(options) > 1 { |
| 881 | opChain.fail(AssertionFailure{ |
| 882 | Type: AssertUsage, |
| 883 | Errors: []error{ |
| 884 | errors.New("unexpected multiple options arguments"), |
| 885 | }, |
| 886 | }) |
| 887 | return newValue(opChain, nil) |
| 888 | } |
| 889 | |
| 890 | value := r.getJSON(opChain, "JSON()", options...) |
| 891 | |
| 892 | return newValue(opChain, value) |
| 893 | } |
| 894 | |
| 895 | func (r *Response) getJSON( |
| 896 | opChain *chain, method string, options ...ContentOpts, |