Проблемы с чтением данных JSON Flutter

Это моя структура данных JSON:

[ [ { «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» } ],

В моей этой функции:

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); }

Когда я запускаю эту строку:

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

Результаты в порядке, т.е.

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)

Но когда я запускаю это:

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

Я получаю такую ​​ошибку:

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

И то же самое для этого:

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

Ошибка:

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

Наиболее важные данные, которые я хочу получить от этого API: debugPrint (list [2] .regDetails [8] .date_of_registration);

Но я получаю такую ​​ошибку:

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

Для некоторых полей данные отображаются правильно, но для некоторых либо значение null, либо ошибка. Что мне не хватает?

Это моя НПО и класс регистрации:

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’], ); } }

Источник: ledsshop.ru

Стиль жизни - Здоровье!