c# - How Can I deserialize a json that is an object with an array? using Newtonsoft xamarin -
i using xamarin forms , newtonsoft deserialize
it doesn't work:
var itens = jsonconvert.deserializeobject<list<model.loja>>(json);
here json:
{ "one": { "two": [ { "cod": 142, "nome": "name", "phone": "23423", "endereco": "address", "cidade": "city" }, { "cod": 142, "nome": "name", "phone": "23423", "endereco": "address", "cidade": "city" } ] } }
your model needs match json structure. try using these classes:
public class rootobject { public 1 one { get; set; } } public class 1 { public list<loja> 2 { get; set; } } public class loja { public int cod { get; set; } public string nome { get; set; } public string phone { get; set; } public string endereco { get; set; } public string cidade { get; set; } }
then deserialize this:
list<loja> items = jsonconvert.deserializeobject<rootobject>(json).one.two;
Comments
Post a Comment