Suppose I have this json saved in my database ?
{
"Type": "IPS",
"Size": "4.7 Inch",
"Protection": "OGS with full lamination technology"
}
The number of the properties are dynamic. Which means for another row my be 5 or 6 properties. Is there any way to loop over it and retrieve them as objects.
So I want to get the type, size, Protection as fileds to create another json format. How can I do this ?
JObject is a good solution. But let us say I am looping thorough rows to create a dynamic object, only for the json field I want to loop over it and add the properties to the dynamic object that i am creating. Can I achieve this ?
For Example:
I ave this
var dataTable= DbHelper.GetDatatable(StoredProcedureName);
now
foreach (DataRow row in rows)
{
var attributes = row["Attributes"].ToString();
var obj = new
{
Id = (int)row["ID"],
Name = row["ProductName"].ToString()
};
list.Add(obj);
}
so row attributes contain the json specified earlier,
Can I loop now to get this final result
var obj = new
{
Id = (int)row["ID"],
Name = row["ProductName"].ToString(),
Type = IPS,
Size = 4.7 Inch,
Protection = OGS with full lamination technology
};
JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(json).