Answers for "ExpandoObject Convert to Json or Json to ExpandoObject"

C#
0

ExpandoObject Convert to Json or Json to ExpandoObject

//  if you add the NewtonSoft.Json NuGet package to your project,
// you can convert your object to a string with this single line of code:
string strCust = JsonConvert.SerializeObject(cust, new ExpandoObjectConverter());

// To convert that string back to your original ExpandoObject, you'll use code like this:
cust = JsonConvert.DeserializeObject<ExpandoObject>(res, new ExpandoObjectConverter());

// This will do a great job of serializing your properties and will normally ignore any methods you added (probably what you want). 
// The one exception is if you have a method that refers to itself (as the example in my previous column did). 
// In that scenario the serialization code will blow up.
Posted by: Guest on April-09-2022

Code answers related to "ExpandoObject Convert to Json or Json to ExpandoObject"

C# Answers by Framework

Browse Popular Code Answers by Language