I am creating a dynamic Jobject from a data set table. The object is expected to have set of 3 key/value pair.
{
"Lowest": "12.50",
"Highest": "",
"Type": "normal"
}
I am looping through a table to generate the array of the object code
dynamic product_Price = new JObject();
JArray product_Price_array = new JArray();
for (int i = 0; i <= ds.Tables[0].Rows.Count-1; i++)
{
product_Price.RemoveAll();
// this is loop through columns to generate the dynamic key value pair of
the object
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
product_Price.Add(ds.Tables[0].Columns[j].ColumnName,ds.Tables[0].Rows[i]
[j].ToString());
}
// now that i have object end of the loop i am adding to the array. but here its always duplicate of object not unique
product_Price_array.Add(product_Price);
}
Current Result : Duplicate jobject is added and its always the last entry from the ds.Tables[0] loop
[
{
"Lowest": "17.50",
"Highest": "",
"Type": "kid"
},
{
"Lowest": "17.50",
"Highest": "",
"Type": "kid"
}
]
I have already tried using list , static object instead of dynamic object.
Expected result
[
{
"Lowest": "12.50",
"Highest": "",
"Type": "normal"
},
{
"Lowest": "17.50",
"Highest": "",
"Type": "kid"
}
]
```