xxxxxxxxxx
using Newtonsoft.Json;
public class MyClass
{
public int MyProperty { get; set; }
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
Note that this approach can be useful for simple objects, but for more complex objects or scenarios, you may want to use a dedicated JSON serialization library or approach, such as creating a custom JSON serializer.