1

How to convert nested dynamic objects into readable data when building email custom tokens without using strongly type models?

Here's my data:

{
  "Id":"126",
  "Fruits":[{"Number":"111", "Name":"Apple"}, {"Number":"112", 
  "Name":"Orange"}],
  "Price":250,
  "EmailAddress":"test126@test.com"
}

and I'm using DeserializeObject

dynamic data = JsonConvert.DeserializeObject<ExpandoObject>(result);

then pass it to the method below:

    protected virtual Dictionary<string, object> BuildCustomTokens(dynamic data)
    {
        var customTokens = new Dictionary<string, object>();
        if(data != null)
        {
            foreach (var dataField in data)
            {
              customTokens.Add($"form_{dataField.Key}", dataField.Value);      
            }
        }

        return customTokens;
    }

It is working, but for array of objects like "Fruits", it is formatted as objects. Sample Email: enter image description here

  • I'd argue this isn't directly an EXM or Sitecore question and more of a general .NET question on how to use dynamic objects. – Pete Navarra Jul 14 at 13:26
  • @PeteNavarra this one is solved. And you're right, this is a .NET Question. What would i do to this question? – ZQuiray Jul 15 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.