parse method

  1. @override
HttpResponse parse(
  1. Response response
)
override

Implementation

@override
HttpResponse parse(Response response) {
  var json = response.data as Map<String, dynamic>?;
  if (json == null) {
    return HttpResponse.failure(errorMsg: '请求的数据为空', errorCode: -1);
  }
  var status = json[_statuskey];
  int code = 0;
  if (status is bool) {
    if (status) {
      code = 1;
    }
  } else {
    if (status == _successcode) {
      code = 1;
    }
  }
  if (code == 1) {
    return HttpResponse.success(json[_datakey] ?? json,
        response: json, reqmsg: json[_msgkey]);
  }
  return HttpResponse.failure(
      errorMsg: (json[_msgkey] != null) ? json[_msgkey] : "",
      errorCode: code,
      data: json[_datakey] ?? json);
}