c# - JSON to List<class> & List<class> to JSON? -
hi guys how work? searched in , promissing doesnt work either.
errormessage:
the deserialized type should normal .net type (i.e. not primitive type integer, not collection type array or list) or dictionary type (i.e. dictionary).
so how split individual objects json?
list<class> = jsonconvert.deserializeobject<list<class>>(json_string)
the json string:
{ "spalten": [{ "nummer": 1, "name": "breite", "typ": "double", "laenge": 0, "einheit": "m", "editierbar": true, "optional": true, "layer": null, "layer_spalte": null, "d_spal_name": null, "d_spal_min": 0, "d_spal_max": null, "d_spal_val": null }, { "nummer": 2, "name": "kommentar", "typ": "string", "laenge": 255, "einheit": null, "editierbar": true, "optional": true, "layer": null, "layer_spalte": null, "d_spal_name": null, "d_spal_min": null, "d_spal_max": null, "d_spal_val": null }] }
here class:
public class config_class { private int _nummer; public int nummer { { return _nummer; } set { _nummer = value; } } private string _name; public string name { { return _name; } set { _name = value; } } private string _typ; public string typ { { return _typ; } set { _typ = value; } } private double _laenge; public double laenge { { return _laenge; } set { _laenge = value; } } private string _einheit; public string einheit { { return _einheit; } set { _einheit = value; } } private bool _editierbar; public bool editierbar { { return _editierbar; } set { _editierbar = value; } } private bool _optional; public bool optional { { return _optional; } set { _optional = value; } } private string _layer; public string layer { { return _layer; } set { _layer = value; } } private int _layer_spalte; public int layer_spalte { { return _layer_spalte; } set { _layer_spalte = value; } } private string _d_spal_name; public string d_spal_name { { return _d_spal_name; } set { _d_spal_name = value; } } private int _d_spal_min; public int d_spal_min { { return _d_spal_min; } set { _d_spal_min = value; } } private int _d_spal_max; public int d_spal_max { { return _d_spal_max; } set { _d_spal_max = value; } } private string _d_spal_val; public string d_spal_val { { return _d_spal_val; } set { _d_spal_val = value; } } }
(i encode again later) thank you!
sorry cannot put comments yet first,you have type mismatch between data , convert class: layer_spalte, d_spal_min , d_spal_max null in data. put try putting array inside class
this code has work you:
public class myclass { public spalten[] spalten { get; set; } } public class spalten { public int nummer { get; set; } public string name { get; set; } public string typ { get; set; } public int laenge { get; set; } public string einheit { get; set; } public bool editierbar { get; set; } public bool optional { get; set; } public string layer { get; set; } public int? layer_spalte { get; set; } public string d_spal_name { get; set; } public int? d_spal_min { get; set; } public int? d_spal_max { get; set; } public string d_spal_val { get; set; } }
and
myclass = jsonconvert.deserializeobject<myclass>(json_string)
Comments
Post a Comment