I have a struct, I want to convert it to JSON and save it as local file.
I couldn't find any source that explain how to convert a C# struct into a JSON.
I am using a console application for that, not a webservice/web, etc.
JavaScriptSerializer Class
var serializer = new JavaScriptSerializer();
YourStruct myStruct = new YourStruct(x,y,z);
var json = serializer.Serialize(myStruct);
JSON.NET
The other alternative JSON.net, it do not depends on System.Web.* assemblies:
YourStruct myStruct = new YourStruct(x,y,z);
var json = JsonConvert.SerializeObject(myStruct);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With