deserialisieren Meine Web-API sendet dieses JSON.Wie JSON (Multilevel) 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"
}
]}
Ich habe versucht, diese JSON mit unter C# -Code deserialisieren
var result = JsonConvert.DeserializeObject<List<AllCategories>>(content);
aber es löst eine Ausnahme.
kann die aktuelle JSON Objekt nicht Deserialisieren (zB { "name": "value"}) in type 'System.Collections.Generic.List`1 [EzyCity.AllCategories]', da der Typ eine JSON Array erfordert (zB [1,2,3]) um richtig zu deserialisieren.
AllCategories Klasse
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; }
}
}
Was sollte getan werden, diese Art von JSON deserialisieren?
mögliche Antwort auf http://stackoverflow.com/questions/31531441/retrieve-required-string-from-bigger-json-string –