0

This is my JSON data Structure:

[
  [
   {
    "nos": 0,
     "name": "A S MUSIC AND DANCE A CULTURAL ORGANIZATION",
    "unique_id": "AN/2020/0259067",
    "reg_details": [
     {
      "registered_with": "Registrar of Societies"
      },
     {
      "type_of_ngo": "Registered Societies (Non-Government)"
     },
     {
      "registration_no": "1534"
       },
       {
         "copy_of_registration_certificate": "Available"
          },
       {
         "copy_of_pan_card": "Available"
        },
       {
        "act_name": "Registration Act,1860"
        },
      {
       "city_of_registration": "Port Blair"
      },
       {
       "state_of_registration": "ANDAMAN & NICOBAR ISLANDS"
        },
         {
       "date_of_registration": "25-05-2016"
        }
      ],  

In my this Function:

 Future<void> _NgoDetail() async {
    String jsonString = await _loadANgoAsset();
    final jsonResponse = json.decode(jsonString);
    var rest = jsonResponse[0] as List;
    List list=[];
    list= rest.map<NGO>((json) => NGO.fromJson(json)).toList();
    debugPrint(list[0].regDetails[1].type_of_ngo);
  }

When I run this line:

debugPrint(list[0].regDetails[1].type_of_ngo);

Results are fine i.e

I/flutter ( 5579): List<dynamic>
I/chatty  ( 5579): uid=10326(com.skillzup.mn.mn) 1.ui identical 117 lines
I/flutter ( 5579): List<dynamic>
I/flutter ( 5579): Registered Societies (Non-Government)

But when I run this:

debugPrint(list[0].regDetails[2].registration_no);

I get this error:

I/flutter ( 5579): List<dynamic>
I/chatty  ( 5579): uid=10326(com.skillzup.mn.mn) 1.ui identical 117 lines
I/flutter ( 5579): List<dynamic>
I/flutter ( 5579): null

And same for this:

debugPrint(list[0].regDetails[3].copy_of_registration_certificate);

Error:

Unhandled Exception: NoSuchMethodError: Class 'RegDetails' has no instance getter 'copy_of_registration_certificate'.

Most Important data that I want from this API is: debugPrint(list[2].regDetails[8].date_of_registration);

But I get this error:

I/flutter ( 5579): List<dynamic>
I/chatty  ( 5579): uid=10326(com.skillzup.mn.mn) 1.ui identical 117 lines
I/flutter ( 5579): List<dynamic>
I/flutter ( 5579): null

For some fields, data is showing correct, but for some, either null or either some error. What am I missing?

This is My NGO and Registeration Class:

class NGO {
  String name;
  String id;
  List<RegDetails> regDetails;
  contactDetails ContactDetails;
  Members members;
  WorkingSectors workingSectors;

  NGO(
      {this.members, this.regDetails, this.name, this.workingSectors, this.ContactDetails, this.id,});

  
  factory NGO.fromJson(Map<String, dynamic> json) {
    var list = json['reg_details'] as List;
    print(list.runtimeType);
    List<RegDetails> regDetails = list.map((i) => RegDetails.fromJson(i)).toList();


    return NGO(
      id: json["unique_id"],
      name: json['name'],
     regDetails: regDetails


    );
  }
}

class RegDetails {
  String registration_no;
  String type_of_ngo;
  String registered_with;
  String copy_of_pan_card;
  String date_of_registration;
  String city_of_registration;
  String state_of_registration;
  String FCRA;

  RegDetails(
      {this.FCRA = 'Not Available', this.city_of_registration, this.copy_of_pan_card, this.date_of_registration, this.registered_with, this.registration_no, this.state_of_registration, this.type_of_ngo});

  factory RegDetails.fromJson(Map<String, dynamic> json){
    return RegDetails(
      registration_no: json['registeration_no'],
      type_of_ngo: json['type_of_ngo'],
      registered_with: json['registered_with'],
      copy_of_pan_card: json['copy_of_pan_card'],
      date_of_registration: json['date_of_registeration'],
      city_of_registration: json['city_of_registeration'],
      state_of_registration: json['state_of_registeration'],
    );
  }
}

1 Answer 1

1

Due to spelling mistake in this block of code

  factory RegDetails.fromJson(Map<String, dynamic> json){
    return RegDetails(
      registration_no: json['registration_no'],
      type_of_ngo: json['type_of_ngo'],
      registered_with: json['registered_with'],
      copy_of_pan_card: json['copy_of_pan_card'],
      date_of_registration: json['date_of_registeration'],
      city_of_registration: json['city_of_registeration'],
      state_of_registration: json['state_of_registeration'],
    );
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I owe you salute!

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.