I use Json(object) to return JsonResult in ASP.Net MVC.
One of the properties in the object is a string that must be Base64 encoded.
public class MyClass
{
public string BlockOfText = "Hello World";
}
Should be converted to the following Json result
{
"BlockOfText" : "SGVsbG8gV29ybGQ="
}
How can I tell Json Serializer to encode the property to Base64?
One solution is to encode your string server based. Before serializing your object just do a :
var instance.BlockOfText64Base = System.Convert.ToBase64String(Encoding.Default.GetBytes(instance.BlockOfText));
return Json(instance, JsonRequestBehavior.AllowGet);
Hope it helps.
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