// ExpectJSONArray tries to unmarshal the response body into a Go slice callback parameter.
// Fail if the body could not be read or if unmarshalling was not possible.
// Returns true if the callback was executed with an array.
555889
func ExpectJSONArray(t T, r *http.Response, callback func(array []interface{})) bool {
	if r == nil {
		logerror(t, serrorf("ExpectJSONArray: no response available"))
		return false
	}
	if r.Body == nil {
		logerror(t, serrorf("ExpectJSONArray: no body to read"))
		return false
	}
	data, err := ioutil.ReadAll(r.Body)
	defer r.Body.Close()
	if err != nil {
		if verboseOnFailure {
			Dump(t, r)
		}
		logerror(t, serrorf("ExpectJSONArray: unable to read response body:%v", err))
		return false
	}
	// put the body back for re-reads
	r.Body = ioutil.NopCloser(bytes.NewReader(data))

	slice := []interface{}{}
	err = json.Unmarshal(data, &slice)
	if err != nil {
		if verboseOnFailure {
			Dump(t, r)
		}
		logerror(t, serrorf("ExpectJSONArray: unable to unmarshal Json:%v", err))
		return false
	}
	callback(slice)
	return true
}
733505
func parseJSON(inputData []byte) (*jsongo.JSONNode, error) {
	root := jsongo.JSONNode{}

	if err := json.Unmarshal(inputData, &root); err != nil {
		return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
	}

	return &root, nil
}
577503
func (self *Commands) IsArray(value interface{}) error {
	if typeutil.IsArray(value) {
		return nil
	} else {
		return fmt.Errorf("Expected array value")
	}
}
338118
func (p *ResponsePath) AsArray() []interface{} {
	if p == nil {
		return nil
	}
	return append(p.Prev.AsArray(), p.Key)
}
34592
func (j *Json) MustArray(args ...[]interface{}) []interface{} {
	var def []interface{}

	switch len(args) {
	case 0:
	case 1:
		def = args[0]
	default:
		log.Panicf("MustArray() received too many arguments %d", len(args))
	}

	a, err := j.Array()
	if err == nil {
		return a
	}

	return def
}
266118
func PrintJSON(in interface{}) error {
	var j []byte
	var err error
	if JSONPretty {
		j, err = json.MarshalIndent(in, JSONPrefix, JSONIndent)
	} else {
		j, err = json.Marshal(in)
	}
	if err != nil {
		return err
	}
	fmt.Println(string(j))
	return nil
}
401182
func ReadJSONBody(r *http.Request, result interface{}) error {
	err := json.NewDecoder(r.Body).Decode(result)
	r.Body.Close()

	if err != nil {
		return err
	}

	return nil
}
391497
func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	if assert.JSONEq(t, expected, actual, msgAndArgs...) {
		return
	}
	t.FailNow()
}
791125
func GuessJSONStream(r io.Reader, size int) (io.Reader, []byte, bool) {
	buffer := bufio.NewReaderSize(r, size)
	b, _ := buffer.Peek(size)
	return buffer, b, hasJSONPrefix(b)
}
561453
func NewStringArray(in interface{}, context *compiler.Context) (*StringArray, error) {
	errors := make([]error, 0)
	x := &StringArray{}
	a, ok := in.([]interface{})
	if !ok {
		message := fmt.Sprintf("has unexpected value for StringArray: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		x.Value = make([]string, 0)
		for _, s := range a {
			x.Value = append(x.Value, s.(string))
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
1223951
func (r *vstResponseElement) ParseArrayBody() ([]driver.Response, error) {
	return nil, driver.WithStack(driver.InvalidArgumentError{Message: "ParseArrayBody not allowed"})
}
1077585
func (m *Message) ReadJSON(v interface{}) error {
	return json.Unmarshal(m.Body, v)
}
1262903
func (ctx *Context) UnJSONBytes(b []byte, v ...interface{}) (interface{}, error) {
	return UnJSONBytes(b, v...)
}
879502
func (c *Client) GetResponseJson(method string, requestUrl string, requestPath string, body string) (responseBody string, err error) {

	//	fmt.Println("method %s, requestPath: %s", requestUrl, requestPath)
	reqest, err := http.NewRequest(method, requestUrl, strings.NewReader(body))
	if err != nil {
		return responseBody, err
	}

	InitBaseHeader(reqest)

	//	如果是post请求，并且有post请求内容则加上Content-MD5头
	if body != "" && method == "POST" {
		reqest.Header.Set("Content-MD5", BodyMd5(body))
	}

	if c.securityToken != "" {
		reqest.Header["x-acs-security-token"] = []string{c.securityToken}
	}

	c.Sign(method, requestPath, reqest, "")

	if method != "POST" {
		reqest.Header.Del("Content-MD5")

	}
	//reqest.Header.Del("Accept-Encoding")
	reqest.Header.Set("Accept-Encoding", "deflate,sdch")

	log.Printf("RequestUrl = %++v", reqest)
	client := &http.Client{}
	t0 := time.Now()
	response, err := client.Do(reqest)
	t1 := time.Now()
	if err != nil {
		return body, err
	}

	if c.debug {
		log.Printf("Invoke %s %s %d (%v)", method, requestUrl, response.StatusCode, t1.Sub(t0))
	}

	rsBody, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return "", err
	}
	//如果状态吗是非200则进行返回值的过滤,使得pop返回的错误和程序的错误输出一致
	if response.StatusCode != 200 {
		err = errors.New("Response status code faild" + string(rsBody))
		type ResultError struct {
			RequestId string `json:"requestId"`
			HostId    string `json:"hostId"`
			Code      string `json:"code"`
			Message   string `json:"Message"`
		}
		var rsError ResultError
		rsBodyString := string(rsBody)
		_ = json.Unmarshal([]byte(rsBodyString), &rsError)

		newResult := ResultModel{
			rsError.Code,
			rsError.Message,
			false,
		}

		resultJson, _ := json.Marshal(newResult)

		return string(resultJson), err

	}

	return string(rsBody), err
}
868921
func (F *Frisby) ExpectHeader(key, value string) *Frisby {
	Global.NumAsserts++
	chk_val := F.Resp.Header.Get(key)
	if chk_val == "" {
		err_str := fmt.Sprintf("Expected Header %q, but it was missing", key)
		F.AddError(err_str)
	} else if chk_val != value {
		err_str := fmt.Sprintf("Expected Header %q to be %q, but got %q", key, value, chk_val)
		F.AddError(err_str)
	}
	return F
}
256480
func (c *Cmd) ExpectSlice(resp ...interface{}) *Cmd {
	response := []interface{}{}
	for _, r := range resp {
		response = append(response, r)
	}
	c.Responses = append(c.Responses, Response{response, nil})
	return c
}
155544
func (that *JSONNode) atArray(key int, val ...interface{}) *JSONNode {
	if that.t == TypeUndefined {
		that.t = TypeArray
	} else if that.t != TypeArray {
		panic(ErrorMultipleType)
	}
	if key < 0 {
		panic(ErrorArrayNegativeValue)
	}
	if key >= len(that.a) {
		newa := make([]JSONNode, key+1)
		for i := 0; i < len(that.a); i++ {
			newa[i] = that.a[i]
		}
		that.a = newa
	}
	return that.a[key].At(val...)
}