c# - How to access children, sub-children and their children from json formatted string -
and values of mpns,upcs,maxsaleprice api link.i getting values in format
foreach (jtoken child in result.children()) { foreach (jtoken grandchild in child) { foreach (jtoken grandgrandchild in grandchild) { var upsc = system.convert.changetype(result["upcs"].tostring(), type); var mpn = system.convert.changetype(result["mpns"].tostring(), type); var maxsaleprice = system.convert.changetype(result["maxsaleprice"].tostring(), type); } } }
but gives values 1 time ,i got values of these objects related api link.
you need replace result["upcs"]
etc. grandgrandchild["upcs"]
:
string url = "https://api.indix.com/v2/offerspremium/products?countrycode=us&q=macys&name=10168--electronics&app_id=dbffc3ab&app_key=6c1608f7ba90259040aa98132f29b433"; var type = typeof(string); webclient wc = new webclient(); jobject results = jsonconvert.deserializeobject<jobject>(wc.downloadstring(url)); foreach (var result in results["result"]["products"]) { string catid = (string)result["categoryid"]; string catname = ddlretailername.selecteditem.text; jtoken fetchrecord = ddlcategories.selecteditem.text; string title = (string)result["title"]; int brandid = (int)result["brandid"]; string brandname = (string)result["brandname"]; var upsc = convert.changetype(result["upcs"].tostring(), type); var mpn = convert.changetype(result["mpns"].tostring(), type); var maxsaleprice = convert.changetype(result["maxsaleprice"].tostring(), type); }
Comments
Post a Comment