如何从flutter的嵌套json输入中获取数据?

ruoxqz4g  于 2023-02-16  发布在  Flutter
关注(0)|答案(1)|浏览(79)

下面是响应如何得到这个数据在Flutter。我想得到图像文件路径的所有领域一样aadhaar,泛卡和企业所有权证明。我需要知道如何得到响应时,它是这样的结构?

{
  "data": {
    "pan": {
      "verified": true,
      "status": "Approve",
      "comment": "ok",
      "holder": "VISHWAJEET VIJAY KOLAPKAR",
      "number": "DYPPK8990B",
      "files": [...,...]
    },
    "aadhar": {
      "verified": true,
      "status": "Approved",
      "comment": "ok",
      "holder": "",
      "number": "000000001112",
      "address": "",
      "dob": "Not available on aadhaar",
      "gender": "MALE",
      "files": [...,...]
    },
    "mobile": {
      "verified": true,
      "status": "In-Progress",
      "comment": "",
      "number": "9527796311",
      "countryCode": "91",
      "holder": "Aniket Ratnakar Baviskar",
      "address": "Plot no.57,, Margashirsh sector, Datt chouk, Cidco, Nashik, Mh-422009",
      "email": "baviskaranu@gmail.com"
    },
    "faceMatch": {
      "verified": "true",
      "status": "In-Progress",
      "comment": "",
      "holder": "Vodafone Vk",
      "matchPercentage": "100.00%",
      "message": "Verification completed with positive result",
      "dob": "NA",
      "files": [...,...]
    },
    "address": {
      "status": "Approved",
      "comment": "ok",
      "verified": false,
      "files": [...,...]
    },
    "bankStatement": {
      "comment": "ok",
      "status": "Approved",
      "verified": false,
      "files": [...,...]
    },
    "business": {
      "documentNumber": "8877",
      "documentType": "Board Resolution (for companies)",
      "status": "Approved",
      "verified": false,
      "files": [...,...]
    },
    "financial": {
      "comment": "ok",
      "status": "Approved",
      "verified": false,
      "files": [...,...]
    },
    "gst": {
      "verified": false,
      "files": [...,...]
    },
    "ownership": {
      "documentNumber": "55555",
      "documentType": "Electricity Bill",
      "status": "Approved",
      "verified": false,
      "files": [...,...]
    },
    "partnership": {
      "comment": "ok",
      "status": "Approved",
      "verified": false,
      "files": [...,...]
    },
    "vintage": {
      "status": "Approved",
      "verified": false,
      "files": [...,...]
    },
    "storeImages": {
      "comment": "ok",
      "status": "Approved",
      "verified": false,
      "files": [...,...]
    }
  },
  "status": true
}
0md85ypi

0md85ypi1#

在你得到数据后把它传给这个函数

final yourModel = yourModelFromMap(jsonString);

它会将json解析为该对象
你可以把它当作

yourModel.data.<any value you want>

import 'dart:convert';

YourModel yourModelFromMap(String str) => YourModel.fromMap(json.decode(str));

String yourModelToMap(YourModel data) => json.encode(data.toMap());

class YourModel {
    YourModel({
        required this.data,
        required this.status,
    });

    Data data;
    bool status;

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

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

class Data {
    Data({
        required this.pan,
        required this.aadhar,
        required this.mobile,
        required this.faceMatch,
        required this.address,
        required this.bankStatement,
        required this.business,
        required this.financial,
        required this.gst,
        required this.ownership,
        required this.partnership,
        required this.vintage,
        required this.storeImages,
    });

    Pan pan;
    Aadhar aadhar;
    Mobile mobile;
    FaceMatch faceMatch;
    Address address;
    Address bankStatement;
    Business business;
    Address financial;
    Gst gst;
    Business ownership;
    Address partnership;
    Vintage vintage;
    Address storeImages;

    factory Data.fromMap(Map<String, dynamic> json) => Data(
        pan: Pan.fromMap(json["pan"]),
        aadhar: Aadhar.fromMap(json["aadhar"]),
        mobile: Mobile.fromMap(json["mobile"]),
        faceMatch: FaceMatch.fromMap(json["faceMatch"]),
        address: Address.fromMap(json["address"]),
        bankStatement: Address.fromMap(json["bankStatement"]),
        business: Business.fromMap(json["business"]),
        financial: Address.fromMap(json["financial"]),
        gst: Gst.fromMap(json["gst"]),
        ownership: Business.fromMap(json["ownership"]),
        partnership: Address.fromMap(json["partnership"]),
        vintage: Vintage.fromMap(json["vintage"]),
        storeImages: Address.fromMap(json["storeImages"]),
    );

    Map<String, dynamic> toMap() => {
        "pan": pan.toMap(),
        "aadhar": aadhar.toMap(),
        "mobile": mobile.toMap(),
        "faceMatch": faceMatch.toMap(),
        "address": address.toMap(),
        "bankStatement": bankStatement.toMap(),
        "business": business.toMap(),
        "financial": financial.toMap(),
        "gst": gst.toMap(),
        "ownership": ownership.toMap(),
        "partnership": partnership.toMap(),
        "vintage": vintage.toMap(),
        "storeImages": storeImages.toMap(),
    };
}

class Aadhar {
    Aadhar({
        required this.verified,
        required this.status,
        required this.comment,
        required this.holder,
        required this.number,
        required this.address,
        required this.dob,
        required this.gender,
        required this.files,
    });

    bool verified;
    String status;
    String comment;
    String holder;
    String number;
    String address;
    String dob;
    String gender;
    List<dynamic> files;

    factory Aadhar.fromMap(Map<String, dynamic> json) => Aadhar(
        verified: json["verified"],
        status: json["status"],
        comment: json["comment"],
        holder: json["holder"],
        number: json["number"],
        address: json["address"],
        dob: json["dob"],
        gender: json["gender"],
        files: List<dynamic>.from(json["files"].map((x) => x)),
    );

    Map<String, dynamic> toMap() => {
        "verified": verified,
        "status": status,
        "comment": comment,
        "holder": holder,
        "number": number,
        "address": address,
        "dob": dob,
        "gender": gender,
        "files": List<dynamic>.from(files.map((x) => x)),
    };
}

class Address {
    Address({
        required this.status,
        required this.comment,
        required this.verified,
        required this.files,
    });

    String status;
    String comment;
    bool verified;
    List<dynamic> files;

    factory Address.fromMap(Map<String, dynamic> json) => Address(
        status: json["status"],
        comment: json["comment"],
        verified: json["verified"],
        files: List<dynamic>.from(json["files"].map((x) => x)),
    );

    Map<String, dynamic> toMap() => {
        "status": status,
        "comment": comment,
        "verified": verified,
        "files": List<dynamic>.from(files.map((x) => x)),
    };
}

class Business {
    Business({
        required this.documentNumber,
        required this.documentType,
        required this.status,
        required this.verified,
        required this.files,
    });

    String documentNumber;
    String documentType;
    String status;
    bool verified;
    List<dynamic> files;

    factory Business.fromMap(Map<String, dynamic> json) => Business(
        documentNumber: json["documentNumber"],
        documentType: json["documentType"],
        status: json["status"],
        verified: json["verified"],
        files: List<dynamic>.from(json["files"].map((x) => x)),
    );

    Map<String, dynamic> toMap() => {
        "documentNumber": documentNumber,
        "documentType": documentType,
        "status": status,
        "verified": verified,
        "files": List<dynamic>.from(files.map((x) => x)),
    };
}

class FaceMatch {
    FaceMatch({
        required this.verified,
        required this.status,
        required this.comment,
        required this.holder,
        required this.matchPercentage,
        required this.message,
        required this.dob,
        required this.files,
    });

    String verified;
    String status;
    String comment;
    String holder;
    String matchPercentage;
    String message;
    String dob;
    List<dynamic> files;

    factory FaceMatch.fromMap(Map<String, dynamic> json) => FaceMatch(
        verified: json["verified"],
        status: json["status"],
        comment: json["comment"],
        holder: json["holder"],
        matchPercentage: json["matchPercentage"],
        message: json["message"],
        dob: json["dob"],
        files: List<dynamic>.from(json["files"].map((x) => x)),
    );

    Map<String, dynamic> toMap() => {
        "verified": verified,
        "status": status,
        "comment": comment,
        "holder": holder,
        "matchPercentage": matchPercentage,
        "message": message,
        "dob": dob,
        "files": List<dynamic>.from(files.map((x) => x)),
    };
}

class Gst {
    Gst({
        required this.verified,
        required this.files,
    });

    bool verified;
    List<dynamic> files;

    factory Gst.fromMap(Map<String, dynamic> json) => Gst(
        verified: json["verified"],
        files: List<dynamic>.from(json["files"].map((x) => x)),
    );

    Map<String, dynamic> toMap() => {
        "verified": verified,
        "files": List<dynamic>.from(files.map((x) => x)),
    };
}

class Mobile {
    Mobile({
        required this.verified,
        required this.status,
        required this.comment,
        required this.number,
        required this.countryCode,
        required this.holder,
        required this.address,
        required this.email,
    });

    bool verified;
    String status;
    String comment;
    String number;
    String countryCode;
    String holder;
    String address;
    String email;

    factory Mobile.fromMap(Map<String, dynamic> json) => Mobile(
        verified: json["verified"],
        status: json["status"],
        comment: json["comment"],
        number: json["number"],
        countryCode: json["countryCode"],
        holder: json["holder"],
        address: json["address"],
        email: json["email"],
    );

    Map<String, dynamic> toMap() => {
        "verified": verified,
        "status": status,
        "comment": comment,
        "number": number,
        "countryCode": countryCode,
        "holder": holder,
        "address": address,
        "email": email,
    };
}

class Pan {
    Pan({
        required this.verified,
        required this.status,
        required this.comment,
        required this.holder,
        required this.number,
        required this.files,
    });

    bool verified;
    String status;
    String comment;
    String holder;
    String number;
    List<dynamic> files;

    factory Pan.fromMap(Map<String, dynamic> json) => Pan(
        verified: json["verified"],
        status: json["status"],
        comment: json["comment"],
        holder: json["holder"],
        number: json["number"],
        files: List<dynamic>.from(json["files"].map((x) => x)),
    );

    Map<String, dynamic> toMap() => {
        "verified": verified,
        "status": status,
        "comment": comment,
        "holder": holder,
        "number": number,
        "files": List<dynamic>.from(files.map((x) => x)),
    };
}

class Vintage {
    Vintage({
        required this.status,
        required this.verified,
        required this.files,
    });

    String status;
    bool verified;
    List<dynamic> files;

    factory Vintage.fromMap(Map<String, dynamic> json) => Vintage(
        status: json["status"],
        verified: json["verified"],
        files: List<dynamic>.from(json["files"].map((x) => x)),
    );

    Map<String, dynamic> toMap() => {
        "status": status,
        "verified": verified,
        "files": List<dynamic>.from(files.map((x) => x)),
    };
}

相关问题