parseResponse method

  1. @override
Map<String, dynamic> parseResponse(
  1. String response
)
override

Parsing of the results returned by the interface.

Implementation

@override
Map<String, dynamic> parseResponse(String response) {
  List<dynamic> resp = jsonDecode(response);
  // 如果请求失败
  if (resp.length == 1) {
    try {
      Map<String, dynamic> status = resp[0][0]["Result"]["ResponseStatus"];
      return {"data": status};
    } catch (e) {
      debugPrint(e.toString());
    }
  }
  // 请求成功时进入如下解析
  List<String> fields = [];
  if (fieldKeys != null) {
    fields = fieldKeys!.split(",");
  }
  List<dynamic> data = [];
  for (var i = 0; i < resp.length; i++) {
    Map<String, dynamic> item = {};
    for (var j = 0; j < fields.length; j++) {
      item[fields[j]] = resp[i][j];
    }
    data.add(item);
  }
  return {"data": data};
}