Does anyone knows how I could encode JSON object to base64?
I have seen a few posts but only works for converting strings.
From @emre
function b64(input)
{
var convert = host.type(“System.Convert”);
var encoding = host.type(“System.Text.Encoding”);
var inputBytes = encoding.UTF8.GetBytes(input);
// return convert.ToBase64String(inputBytes);
For all intents and purposes, JSON is a string until it’s deserialised/converted into an object. Passing your JSON data direct to the function should work.
function b64ToString(b64Data) {
var convert = host.type("System.Convert");
var encoding = host.type("System.Text.Encoding");
var bytes = convert.FromBase64String(b64Data);
var json = encoding.UTF8.GetString(bytes);
var obj = JSON.parse(json);
}
that will take a Base64 encoded string (UTF8) and deserialise to obj