Parse a Json String to create a new custom object c# -
i returning json string webmethod in webforms , want take json string , parse custom order
objects.
i have class:
public class order { public string item { get; set; } public string color { get; set; } public string qty { get; set; } public string size { get; set; } }
and webmethod:
[webmethod] public static string sendorder(string json) { list<order> orders = new list<order>(); return json; }
i passing string:
{ json: [ { "item":"nike polo #286772 - women's dri-fit micro pique short sleeved polo", "size":"xl", "color":"light blue", "quantity":"3" }, { "item":"port authority women's jacket #l790 - black", "size":"medium", "color":"black", "quantity":"3" } ] }
i want loop through string , creating new orders.
what best way this?
that json little oddly formatted maps following classes (using http://json2csharp.com):
public class json { public string item { get; set; } public string size { get; set; } public string color { get; set; } public string quantity { get; set; } } public class rootobject { public list<json> json { get; set; } }
i'm not sure why have top-level variable named json
, whatever.
at point use json.net deserialize structure.
jsonconvert.deserializeobject<rootobject>(yourjsonstring);
if want rename object json
order
you'll need use attribute that. don't recall name off top of head should easy find in json.net documentation.
Comments
Post a Comment