I have an api that returns me a json with information about the data transition and an array with data
{
"code": "200",
"result": true,
"message": "",
"data": {
"item": [
{
"id": "5",
"descricao": "TesteDesc",
"observacao": "TesteObs",
"status": "1"
},
{
"id": "7",
"descricao": "TesteDesc",
"observacao": "TesteObs",
"status": "1"
},
],
"count": 2
}
}
I have a class that is referring to the return of items
class Category
{
public int Id { get; set; }
public string Descricao { get; set; }
public int Status { get; set; }
public string Observacao { get; set; }
}
Main.cs
var stringJson = await response.Content.ReadAsStringAsync();
my string stringJson gets the following value
"
{"code":"200","result":true,"message":"","data":{"item":[{"id":"5","descricao":"TesteDesc","observacao":"TesteObs","status":"1"}],"count":2}}"
but when I try to convert
var Data = JsonConvert.DeserializeObject<IEnumerable<Category>>(stringJson);
error is displayed
Erro: cannot deserialize the current json object (e.g.
{"name":"value"}) into type ...
How can I create an array of objects with json data?
taking only the date and item
is it possible for me to retrieve the values formally alone, for example I make a variable bool status = jsonConvert.get ("status"); something like that?
See Question&Answers more detail:
os