0

{ "data": { "Address": "ff9", "CityID": "1", "CityName": "Ahmedabad", "CompanyName": "bs Soffy", "CreditDays": "12", "CusotmerID": "45", "Email": "[email protected]", "GSTNo": "1234", "IsApproved": "False", "Lat": "", "Long": "", "Mobile": "1234567890", "Pincode": "", "Route": "", "StateID": "1", "StateName": "Gujrat", "UniqueNumber": "" }, "message": "Data updated successfully", "status": 200 }

List<GetCustomer> Customerlist = [];

Future<List<GetCustomer>> getPostApi() async {
final response = await http.post(
    Uri.parse(
        'XYZ'),
    headers: {
      "Content-Type": "application/json",
      "Charset": "utf-8",
    },
    body: (jsonEncode({'UserID': 1})));

if (response.statusCode == 200) {
  // Map<String, dynamic> map = json.decode(response.body);

  Map<String, dynamic> map =
      new Map<String, dynamic>.from(json.decode(response.body));

  List<dynamic> data = map["data"];

  Customerlist.clear();
  for (var i in data) {
    Customerlist.add(GetCustomer.fromJson(i));
  }
  return Customerlist;
} else {
  return Customerlist;
}

} -> Eror When Calling

3
  • Present the code of what you have tried so far. Commented Jul 2, 2022 at 14:07
  • you need to show some code, then only we can help you. Commented Jul 2, 2022 at 14:26
  • Check My Edited Post Commented Jul 2, 2022 at 16:09

1 Answer 1

3

You can use app.quicktype.io or any other online sites for parsing your model so fast. Otherwise you need to write manually.

// To parse this JSON data, do
//
//     final data = dataFromJson(jsonString);

import 'dart:convert';

Data dataFromJson(String str) => Data.fromJson(json.decode(str));

String dataToJson(Data data) => json.encode(data.toJson());

class Data {
    Data({
        this.data,
        this.message,
        this.status,
    });

    DataClass data;
    String message;
    int status;

    factory Data.fromJson(Map<String, dynamic> json) => Data(
        data: DataClass.fromJson(json["data"]),
        message: json["message"],
        status: json["status"],
    );

    Map<String, dynamic> toJson() => {
        "data": data.toJson(),
        "message": message,
        "status": status,
    };
}

class DataClass {
    DataClass({
        this.address,
        this.cityId,
        this.cityName,
        this.companyName,
        this.creditDays,
        this.cusotmerId,
        this.email,
        this.gstNo,
        this.isApproved,
        this.lat,
        this.long,
        this.mobile,
        this.pincode,
        this.route,
        this.stateId,
        this.stateName,
        this.uniqueNumber,
    });

    String address;
    String cityId;
    String cityName;
    String companyName;
    String creditDays;
    String cusotmerId;
    String email;
    String gstNo;
    String isApproved;
    String lat;
    String long;
    String mobile;
    String pincode;
    String route;
    String stateId;
    String stateName;
    String uniqueNumber;

    factory DataClass.fromJson(Map<String, dynamic> json) => DataClass(
        address: json["Address"],
        cityId: json["CityID"],
        cityName: json["CityName"],
        companyName: json["CompanyName"],
        creditDays: json["CreditDays"],
        cusotmerId: json["CusotmerID"],
        email: json["Email"],
        gstNo: json["GSTNo"],
        isApproved: json["IsApproved"],
        lat: json["Lat"],
        long: json["Long"],
        mobile: json["Mobile"],
        pincode: json["Pincode"],
        route: json["Route"],
        stateId: json["StateID"],
        stateName: json["StateName"],
        uniqueNumber: json["UniqueNumber"],
    );

    Map<String, dynamic> toJson() => {
        "Address": address,
        "CityID": cityId,
        "CityName": cityName,
        "CompanyName": companyName,
        "CreditDays": creditDays,
        "CusotmerID": cusotmerId,
        "Email": email,
        "GSTNo": gstNo,
        "IsApproved": isApproved,
        "Lat": lat,
        "Long": long,
        "Mobile": mobile,
        "Pincode": pincode,
        "Route": route,
        "StateID": stateId,
        "StateName": stateName,
        "UniqueNumber": uniqueNumber,
    };
}



Sign up to request clarification or add additional context in comments.

1 Comment

Pleas Check edited My Post ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.