带有Json的HTTP POST方法-Flutter / Dart

问题描述 投票:0回答:2

带有Json的HTTP POST方法-Flutter / Dart:

 Future<List<dynamic>> requestMethodtwo() async {
    var url = "";
    var body = json.encode({"finYr": "6", "UserID": "1"});
    setState(() {
      isLoading = true;
    });
    Map<String, String> headers = {
      'Content-type': 'application/json',
      'Accept': 'application/json',
    };
    final response =
    await http.post(url, body: body, headers: headers);
    final responseJson = json.decode(response.body);
    final items = json.decode(response.body).cast<Map<String, dynamic>>();
    List<dynamic> listOfString = items.map((json) {
      return json['rows'];
    }).toList();
    print(listOf[enter image description here][1]String);
    print(response.statusCode);
    if (response.statusCode == 200) {
    }
    else {
      throw Exception('Failed to load internet');
    }
    return listOfString;
  }
My Api Call 
[
    {
        "status": 200,
        "msg": "Ok",
        "rows": [
            {
                "lid": "11031",
                "CompanyName": "WALLS ICE CREAM",
                "LeadSourceName": "Website",
                "LeadSourceValue": "ONLINE ADS"
            },
            {
               "lid": "11032",
                "CompanyName": "WALLS ICE CREAM",
                "LeadSourceName": "Website",
                "LeadSourceValue": "ONLINE ADS"
            },
            {
                 "lid": "11034",
                "CompanyName": "WALLS ICE CREAM",
                "LeadSourceName": "Website",
                "LeadSourceValue": "ONLINE ADS"
            }
        ],
        "sql": "gg",
        "reserved": null
    }
]
flutter dart
2个回答
0
投票

您可以在下面复制粘贴运行完整代码假设您的响应JSON字符串是这样的,它是数组


0
投票

步骤1:创建您的响应模型类例如样本Json结构//在您的响应结果中是第

© www.soinside.com 2019 - 2024. All rights reserved.