Saltar al contenido

Ejemplo de scripting en Jitterbit App Builder - Convertir valor codificado en Base64 a texto

Este Plugin de respuesta REST está diseñado para convertir un valor codificado en Base64 a texto. En el ejemplo específico donde se utilizó este script, el valor codificado era la codificación Base64 de XML en una respuesta JSON REST.

#r "Newtonsoft.Json.dll"
using System;
using System.Text;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

string columnToDecode = "file_base64";

string originalContent = await Response.Content.ReadAsStringAsync();
var jobject = JObject.Parse(originalContent);

// Decode the field in the json
byte[] data = Convert.FromBase64String(jobject[columnToDecode].ToString());
string decodedString = Encoding.UTF8.GetString(data);

// Replace the data in json with the decoded value
jobject[columnToDecode] = decodedString;

// Update the response
string newJson = jobject.ToString();
Response.Content = new StringContent(newJson, Encoding.UTF8, "application/json");

Limitaciones

Se espera que este Plugin no funcione con codificación binaria.