La mia API Web sta inviando questo JSON.Come deserializzare JSON (multi livello) in C#
{ "data":[
{
"cat_id":"1",
"category":"Clothing",
"img_url":"sampleUrl.com"
},
{
"cat_id":"2",
"category":"Electronic Shop",
"img_url":"sampleUrl.com"
},
{
"cat_id":"3",
"category":"Grocery",
"img_url":"sampleUrl.com"
},
{
"cat_id":"4",
"category":"Hardware",
"img_url":"sampleUrl.com"
}
]}
ho cercato di deserializzare questo JSON usando sotto C# codice
var result = JsonConvert.DeserializeObject<List<AllCategories>>(content);
ma viene generata un'eccezione.
Impossibile deserializzare l'oggetto JSON corrente (ad esempio, { "name": "valore"}) in tipo 'System.Collections.Generic.List`1 [EzyCity.AllCategories]' perché il tipo richiede una matrice JSON (es. [1,2,3]) per deserializzare correttamente.
AllCategories classe
public class AllCategories
{
private string cat_id;
private string category;
private string img_url;
public string Cat_Id
{
get { return cat_id; }
set { cat_id = value; }
}
public string Category
{
get { return category; }
set { category = value; }
}
public string Image_Url
{
get { return img_url; }
set { img_url = value; }
}
}
Che cosa dovrebbe essere fatto per deserializzare questo tipo di JSON?
risposta possibile a http://stackoverflow.com/questions/31531441/retrieve-required-string-from-bigger-json-string –