Tom Sage
asked on
Creating and using List of Expando objects
I am trying to create a Json object in C# that I will convert to XML. I have a repeating set of Fees that I need to add to the json object.
Here is my code so far:
No sure what else is needed. Supply a different example if that is easier for you.
Thank you
Here is my code so far:
root.Deal.Fees = new ExpandoObject();
List<ExpandoObject> feeArray = new List<ExpandoObject>();
foreach (DataRow ro in ds.Tables["fees"].Rows)
{
root.Deal.Fees.DealFees.Fee.Description = ro["fee_type"].ToString();;
root.Deal.Fees.DealFees.Fee.Amount = ro["amount"].ToString();
feeArray.Add(root.Deal.Fees);
}
No sure what else is needed. Supply a different example if that is easier for you.
Thank you
ASKER
Hi Dirk - I will investigate those links.
My input is json and output is XML.
I will update this topic by tomorrow.
Thanks
My input is json and output is XML.
I will update this topic by tomorrow.
Thanks
If your input is Json, use Newtonsoft.Json to deserialize the Json to an object and then serialize that object to XML. I'm not sure if there is a direct way to go from Json to XML.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great I will check it out. Thanks
ASKER
Thanks for your help Dirk !
Only solution
You can then easily serialize and deserialize your feeArray object. Have a look at this link: http://www.newtonsoft.com/json/help/html/SerializingJSON.htm
But if it is XML that you are after, have a look at doing it directly: https://support.microsoft.com/en-ph/help/815813/how-to-serialize-an-object-to-xml-by-using-visual-c
So I'm not sure if you want it serialized to JSON or XML. Json is smaller in size than XML. Many other languages can consume Json out of the box, so you need to make a decision based on your unique situation.
Lastly, if you use Newtonsoft.Json, you can perform LINQ queries against your JSON object, which is quite cool.