Deserialize JSON with Newtonsoft JSON

Asked

Viewed 46 times

3

I am trying to make an deserialize, to create a list with the contents of this JSON. However, everything arrives to the list as null. I’m gonna let down what I’ve got so far.

I have the following JSON:

{
    "result": [
        {
            "A": "323",
            "B": "919",
            "C": "teste"
        },
        {
            "A": "325",
            "B": "919",
            "C": "testando"
        },
        {
            "A": "453",
            "B": "919",
            "C": "ola mundo"
        }
    ],
    "time": {
        "start": 1573048358.63732,
        "finish": 1573048358.673811,
        "duration": 0.036490917205810547,
        "processing": 0.0077030658721923828,
        "date_start": "2019-11-06T16:52:38+03:00",
        "date_finish": "2019-11-06T16:52:38+03:00"
    }
}

Controller:

// RECEBE OS PRODUTOS DO NEGOCIO
var json = await http.GetStringAsync("CAMINHO DO JSON");
var produto = JsonConvert.DeserializeObject<Empresa.Produto>(json);

return produto.ID;

Class:

public class Empresa

{
    public class Produto
    {
        public string A { get; set; }
        public string B { get; set; }
        public string C { get; set; }
    }
}

1 answer

1

// RESOLVED! //

The only change in the code I made was in the class structure, which with the change became:

public class Empresa
    {
        public class Produto
        {
            public List<result_classe> result { get; set; }

            public class result_classe
            {
                public string A { get; set; }
                public string B { get; set; }
                public string C { get; set; }
            }
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.