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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -