Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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.
Source by visualstudiomagazine.com #
 
PREVIOUS NEXT
Tagged: #ExpandoObject #Convert #Json #Json #ExpandoObject
ADD COMMENT
Topic
Name
8+7 =