skip to Main Content
Shippingmodel shippingmodelFromJson(String str) => Shippingmodel.fromJson(json.decode(str));

String shippingmodelToJson(Shippingmodel data) => json.encode(data.toJson());

class Shippingmodel {
  Shippingmodel({
    this.sellerShipping,
    this.result,
    this.shippingType,
    this.value,
    this.valueString,
  });

  Map<String, List<SellerShipping>> sellerShipping;
  bool result;
  String shippingType;
  int value;
  String valueString;

  factory Shippingmodel.fromJson(Map<String, dynamic> json) => Shippingmodel(
    sellerShipping: Map.from(json["seller_shipping"]).map((k, v) => MapEntry<String, List<SellerShipping>>(k, List<SellerShipping>.from(v.map((x) => SellerShipping.fromJson(x))))),
    result: json["result"],
    shippingType: json["shipping_type"],
    value: json["value"],
    valueString: json["value_string"],
  );

  Map<String, dynamic> toJson() => {
    "seller_shipping": Map.from(sellerShipping).map((k, v) => MapEntry<String, dynamic>(k, List<dynamic>.from(v.map((x) => x.toJson())))),
    "result": result,
    "shipping_type": shippingType,
    "value": value,
    "value_string": valueString,
  };
}

class SellerShipping {
  SellerShipping({
    this.code,
    this.name,
    this.price,
    this.deadline,
    this.erroMsg,
  });

  String code;
  String name;
  String price;
  String deadline;
  String erroMsg;

  factory SellerShipping.fromJson(Map<String, dynamic> json) => SellerShipping(
    code: json["code"],
    name: json["name"],
    price: json["price"],
    deadline: json["deadline"],
    erroMsg: json["erroMsg"],
  );

  Map<String, dynamic> toJson() => {
    "code": code,
    "name": name,
    "price": price,
    "deadline": deadline,
    "erroMsg": erroMsg,
  };
}

This is the json data model. I’m perplexed as to how to retrieve anything, say price from sellerShipping. I’m calling it from a repository and passing the response. body. Any help would be appreciated!

This is the json data model. I’m perplexed as to how to retrieve anything, say price from sellerShipping. I’m calling it from a repository and passing the response. body. Any help would be appreciated!

2

Answers


  1. Chosen as BEST ANSWER

    To anybody stuck with this issue, the answer on this post helped me out, the one with the flutter example.

    Get the length of List that exists in Map<String,List<Object>> in Flutter


  2. i assume you want this. if you mean something else, comment in this answer. i will try to help.

    var json = jsonDecode(response.body);
    Shippingmodel _shippingmodel = Shippingmodel.fromJson(json);
    String _price = _shippingmodel.sellerShipping.price;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search