0
I’m tantalizing to deserialize a JSON file, may I’m having this error "Newtonsoft.Json.Jsonserializationexception: 'Cannot deserialize the Current JSON Object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Consoleapp1.Program+detail]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly."
{
"detalhes": [],
"subdetalhes": {
"carro": {
"descricao": "carro",
"detalhes": [
{
"codigo": 00000,
"descricao": "CREDENCIADO",
"data": "2019-01-15 01:05:36",
"ticket": "00000",
"mensal": true,
"terminal": {
"codigo": 5,
"tipo": ""
},
"setor": {
"descricao": "ESTACIONAMENTO"
},
"tipoVeiculo": {
"descricao": "AUTOMOVEL"
},
"tipoServico": {
"descricao": "COMUM"
}
},
}
],
"subdetalhes": {},
"quantidade": 1745
},
"caminhao": {
"descricao": "caminhao",
"detalhes": [],
"subdetalhes": {},
"quantidade": 0
},
"moto": {
"descricao": "moto",
"detalhes": [],
"subdetalhes": {},
"quantidade": 0
}
},
"quantidade": 1745
}
This is the JSON file, but it has more than one [] and I’m not able to create classes to deserialize
public class detalhe{
public List<Entrada> entrada { get; set; }
}
public class Entrada{
public int codigo { get; set; }
public string descricao { get; set; }
public string data { get; set; }
public int ticket { get; set; }
public bool mensal { get; set; }
}
{
var client = new RestClient("https://xxxxxxxxxxxxxxxxxxxxxxxxxxxr/pxxxxxxxx/xxxxxxx/xxxxxx/xxxxxxx/51/20190101/xxxxxx/?detalhe=true");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==");
IRestResponse response = client.Execute(request);
//Console.WriteLine(response.Content);
var records = JsonConvert.DeserializeObject<List<detalhe>>(response.Content);
foreach (var r in records)
{
Console.Read();
Console.WriteLine(response.Content);
}
} ```
Your classes do not match anything with the json presented... as you expect to perform this operation without doing manual mapping?
– Leandro Angelo
You can map your class with the help of online services, http://json2csharp.com/
– Ernesto Casanova