How to get certain values from json string, and insert it into a dictionary in C# ?
The following is my json string:
[{"RowNum":7,"Item_Code":"m2","Item_Name":"Mixer","Item_ProductBrand":0,"Item_Category":1,"Item_Unit":0,"Item_Blocked":false,"Costing_Method":0,"Standard_Cost":0.0,"Retail_UnitPrice":10.0,"Dealer_UnitPrice":20.0,"Distributor_UnitPrice":30.0,"Safety_Stock":0.0,"Safety_LeadTime":0,"Reorder_Point":0.0,"Reorder_Quantity":0.0,"BusinessUnitID":"1","CompanyID":"1","RowVersion":1},{"RowNum":8,"Item_Code":"t1","Item_Name":"Television","Item_ProductBrand":0,"Item_Category":1,"Item_Unit":0,"Item_Blocked":false,"Costing_Method":0,"Standard_Cost":0.0,"Retail_UnitPrice":40.0,"Dealer_UnitPrice":50.0,"Distributor_UnitPrice":60.0,"Safety_Stock":0.0,"Safety_LeadTime":0,"Reorder_Point":0.0,"Reorder_Quantity":0.0,"BusinessUnitID":"1","CompanyID":"1","RowVersion":1}]
Currently I have two json objects in this string. It is actually a string created in the form of JSON Array.
I have a Dictionary, into which I need to add Item_Name and Item_Code. How to do that?
I was successful in creating the Dictionary and adding/mapping elements from the string. But, I cannot populate the DropDownList. My code is :
string items = GetJSON(url);
Dictionary<string, string>[] itemDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>[]>(items);
DropDownList3.DataSource = itemDictionary;
DropDownList3.DataTextField = "Item_Name";
DropDownList3.DataValueField = "Item_Code";
DropDownList3.DataBind();
This is not working. How to correct this ?