2
Segue json:
[
{
"id":"BKA-EU8IED8ZD21Q",
"agencyNumber":"1",
"accountNumber":"1",
"holder":{
"thirdParty":false,
"taxDocument":{
"number":"783.121.360-02",
"type":"CPF"
},
"fullname":"Leandro da silva"
},
"status":"NOT_VERIFIED",
"createdAt":"2018-08-23T10:59:01.000-03:00",
"accountCheckNumber":"1",
"_links":{
"self":{
"href":""
}
},
"bankName":"BANCO DO BRASIL S.A.",
"type":"SAVING",
"agencyCheckNumber":"1",
"bankNumber":"001"
},
{
"id":"BKA-3KF1C4O7F247",
"agencyNumber":"1",
"accountNumber":"1",
"holder":{
"thirdParty":false,
"taxDocument":{
"number":"783.121.360-02",
"type":"CPF"
},
"fullname":"Leandro da silva"
},
"status":"NOT_VERIFIED",
"createdAt":"2018-08-24T14:06:25.000-03:00",
"accountCheckNumber":"1",
"_links":{
"self":{
"href":""
}
},
"bankName":"BANCO BRADESCO S.A.",
"type":"CHECKING",
"agencyCheckNumber":"1",
"bankNumber":"237"
},
{
"id":"BKA-ZFYCD7NIPK9H",
"agencyNumber":"1",
"accountNumber":"1",
"holder":{
"thirdParty":false,
"taxDocument":{
"number":"783.121.360-02",
"type":"CPF"
},
"fullname":"Leandro da silva"
},
"status":"NOT_VERIFIED",
"createdAt":"2018-08-24T15:06:52.000-03:00",
"accountCheckNumber":"1",
"_links":{
"self":{
"href":""
}
},
"bankName":"BANCO BRADESCO S.A.",
"type":"CHECKING",
"agencyCheckNumber":"1",
"bankNumber":"237"
},
{
"id":"BKA-0E7J1UH937M1",
"agencyNumber":"1",
"accountNumber":"1",
"holder":{
"thirdParty":false,
"taxDocument":{
"number":"783.121.360-02",
"type":"CPF"
},
"fullname":"Leandro da silva"
},
"status":"NOT_VERIFIED",
"createdAt":"2018-08-24T15:08:01.000-03:00",
"accountCheckNumber":"1",
"_links":{
"self":{
"href":""
}
},
"bankName":"BANCO BRADESCO S.A.",
"type":"CHECKING",
"agencyCheckNumber":"1",
"bankNumber":"237"
},
{
"id":"BKA-OIGOJHQB82FS",
"agencyNumber":"1",
"accountNumber":"1",
"holder":{
"thirdParty":false,
"taxDocument":{
"number":"783.121.360-02",
"type":"CPF"
},
"fullname":"Leandro da silva"
},
"status":"NOT_VERIFIED",
"createdAt":"2018-08-24T16:00:27.000-03:00",
"accountCheckNumber":"1",
"_links":{
"self":{
"href":""
}
},
"bankName":"BANCO BRADESCO S.A.",
"type":"CHECKING",
"agencyCheckNumber":"1",
"bankNumber":"237"
},
{
"id":"BKA-IWYY1DPM1S68",
"agencyNumber":"12345",
"accountNumber":"12345678",
"holder":{
"thirdParty":false,
"taxDocument":{
"number":"783.121.360-02",
"type":"CPF"
},
"fullname":"Leandro da silva"
},
"status":"NOT_VERIFIED",
"createdAt":"2018-08-25T16:13:51.000-03:00",
"accountCheckNumber":"7",
"_links":{
"self":{
"href":""
}
},
"bankName":"BANCO BRADESCO S.A.",
"type":"CHECKING",
"agencyCheckNumber":"0",
"bankNumber":"237"
}
]
Follows the classes:
public class Rootobject
{
public Class1[] Property1 { get; set; }
}
public class Class1
{
public string id { get; set; }
public string agencyNumber { get; set; }
public string accountNumber { get; set; }
public Holder holder { get; set; }
public string status { get; set; }
public DateTime createdAt { get; set; }
public string accountCheckNumber { get; set; }
public _Links _links { get; set; }
public string bankName { get; set; }
public string type { get; set; }
public string agencyCheckNumber { get; set; }
public string bankNumber { get; set; }
}
public class Holder
{
public bool thirdParty { get; set; }
public Taxdocument taxDocument { get; set; }
public string fullname { get; set; }
}
public class Taxdocument
{
public string number { get; set; }
public string type { get; set; }
}
public class _Links
{
public Self self { get; set; }
}
public class Self
{
public string href { get; set; }
}
Follow the logic to deserialize:
var result = JsonConvert.DeserializeObject<Rootobject[]>(json);
Each array has its own property Property1
and this property is always null.
How can I fix this ?
The informed json appears to be an object array
Classe1
. Try the following:var result = JsonConvert.DeserializeObject<Classe1[]>(json)
;– Roberto Braga
@Robertobraga makes sense
– Matheus Miranda