I am getting null data from a complex json, here's the json. When I have try to parse this I got null. Please have a look blow json.
{
"billInfoList": [
{
"accountBalance": 0,
"address": {
"street": "nd",
"complement": "df",
"city": "dsfs",
"neighborhood": "cxcnx",
"isForcedAddress": false,
"state": "ARE",
"zip": "00000",
"country": "hchchc",
"district": "ccc"
},
"billDay": 0,
"billFrequency": 0,
"billNumber": "hcc",
"billType": 1cxc1,
"creationDate": "2019-02-04",
"dueDate": "2019-02-19",
"servicePeriodEnd": "2019-02-04",
"servicePeriodStart": "2019-01-29",
"status": "Paid",
"value": 0,
"valueDisputed": 0,
"valueOpen": 0
},
{
"accountBalance": 0,
"address": {
"street": "cxcvenciones ",
"complement": "Test124",
"city": "Arequipa",
"neighborhood": "Test4",
"isForcedAddress": false,
"state": "ARE",
"zip": "00320",
"country": "PE",
"district": "cquipa"
},
"billDay": 0,
"billFrequency": 0,
"billNumber": "dfs678",
"billType": fds1,
"billURL": "http://",
"creationDate": "2019-01-29",
"dueDate": "2019-02-13",
"servicePeriodEnd": "2019-01-29",
"servicePeriodStart": "2019-01-29",
"status": "Paid",
"value": 3.6,
"valueDisputed": 0,
"valueOpen": 0
},
{
"accountBalance": 0,
"address": {
"street": "fsdnciones ",
"complement": "Test124",
"city": "dfspa",
"neighborhood": "Test4",
"isForcedAddress": false,
"state": "ARE",
"zip": "3200",
"country": "PE",
"district": "requipa"
},
"billDay": 0,
"billFrequency": 0,
"billNumber": "323677",
"billType": 341,
"creationDate": "2019-01-29",
"dueDate": "2019-02-13",
"servicePeriodEnd": "2019-01-29",
"servicePeriodStart": "2019-01-29",
"status": "Pd",
"value": 0,
"valueDisputed": 0,
"valueOpen": 0
}
],
"TransactionSequenceId": "hrhrhrh9",
"ResponseCode": "hfhf00",
"ResponseMessage": "Request Processed successfully"
}
I have generate Model class: https://javiercbk.github.io/json_to_dart/
After generate the Model class create a new class name ModelClass.
Another class name APiResponse and write the code: This class get api response and return response: APiResponse.fromJson(jsonDecode(response.body));
I have try to parse:
APiResponse.fromJson(Map<String, dynamic> json)
: results = new ModelClass.fromJson(json),
error = "";
ModelClass:
class ModelClass {
List<BillInfoList> billInfoList;
String transactionSequenceId;
String responseCode;
String responseMessage;
ModelClass (
{this.billInfoList,
this.transactionSequenceId,
this.responseCode,
this.responseMessage});
ModelClass.fromJson(Map<String, dynamic> json) {
if (json['billInfoList'] != null) {
billInfoList = new List<BillInfoList>();
json['billInfoList'].forEach((v) {
billInfoList.add(new BillInfoList.fromJson(v));
});
}
transactionSequenceId = json['TransactionSequenceId'];
responseCode = json['ResponseCode'];
responseMessage = json['ResponseMessage'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.billInfoList != null) {
data['billInfoList'] = this.billInfoList.map((v) => v.toJson()).toList();
}
data['TransactionSequenceId'] = this.transactionSequenceId;
data['ResponseCode'] = this.responseCode;
data['ResponseMessage'] = this.responseMessage;
return data;
}
}
class BillInfoList {
int accountBalance;
Address address;
int billDay;
int billFrequency;
String billNumber;
int billType;
String creationDate;
String dueDate;
String servicePeriodEnd;
String servicePeriodStart;
String status;
double value;
int valueDisputed;
int valueOpen;
String billURL;
BillInfoList(
{this.accountBalance,
this.address,
this.billDay,
this.billFrequency,
this.billNumber,
this.billType,
this.creationDate,
this.dueDate,
this.servicePeriodEnd,
this.servicePeriodStart,
this.status,
this.value,
this.valueDisputed,
this.valueOpen,
this.billURL});
BillInfoList.fromJson(Map<String, dynamic> json) {
accountBalance = json['accountBalance'];
address =
json['address'] != null ? new Address.fromJson(json['address']) : null;
billDay = json['billDay'];
billFrequency = json['billFrequency'];
billNumber = json['billNumber'];
billType = json['billType'];
creationDate = json['creationDate'];
dueDate = json['dueDate'];
servicePeriodEnd = json['servicePeriodEnd'];
servicePeriodStart = json['servicePeriodStart'];
status = json['status'];
value = json['value'];
valueDisputed = json['valueDisputed'];
valueOpen = json['valueOpen'];
billURL = json['billURL'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['accountBalance'] = this.accountBalance;
if (this.address != null) {
data['address'] = this.address.toJson();
}
data['billDay'] = this.billDay;
data['billFrequency'] = this.billFrequency;
data['billNumber'] = this.billNumber;
data['billType'] = this.billType;
data['creationDate'] = this.creationDate;
data['dueDate'] = this.dueDate;
data['servicePeriodEnd'] = this.servicePeriodEnd;
data['servicePeriodStart'] = this.servicePeriodStart;
data['status'] = this.status;
data['value'] = this.value;
data['valueDisputed'] = this.valueDisputed;
data['valueOpen'] = this.valueOpen;
data['billURL'] = this.billURL;
return data;
}
}
class Address {
String street;
String complement;
String city;
String neighborhood;
bool isForcedAddress;
String state;
String zip;
String country;
String district;
Address(
{this.street,
this.complement,
this.city,
this.neighborhood,
this.isForcedAddress,
this.state,
this.zip,
this.country,
this.district});
Address.fromJson(Map<String, dynamic> json) {
street = json['street'];
complement = json['complement'];
city = json['city'];
neighborhood = json['neighborhood'];
isForcedAddress = json['isForcedAddress'];
state = json['state'];
zip = json['zip'];
country = json['country'];
district = json['district'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['street'] = this.street;
data['complement'] = this.complement;
data['city'] = this.city;
data['neighborhood'] = this.neighborhood;
data['isForcedAddress'] = this.isForcedAddress;
data['state'] = this.state;
data['zip'] = this.zip;
data['country'] = this.country;
data['district'] = this.district;
return data;
}
}