Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    May 08, 2015 @ 11:54
    Søren Kottal
    0

    IContent does not contain a definition for SetValue when trying to add serialized Json

    For some reason, I can't add JSON data serialized to a string in SetValue().

    Look at this example:

     

            var newEntries = JsonConvert.SerializeObject(entries).ToString();

            var newEntries2 = "{\"Entries\":[{\"Name\":null,\"Phone\":\"123455\",\"Message\":\"Test\",\"Date\":\"2015-05-08T11:47:50.0421163+02:00\"}]}";


            property.SetValue("ctaEntries", newEntries);
            property.SetValue("ctaEntries", newEntries2);

    Line 4 (newEntries2) works, Line 3 doesn't. 

     

    I don't get it...

     

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Dec 01, 2015 @ 13:49
    Søren Kottal
    100

    Stumbled on to this problem again, the solution seems to be to write the following in stead:

    property.Properties["ctaEntries"].Value = newEntries;

  • Jamie Attwood 201 posts 493 karma points c-trib
    Jul 12, 2023 @ 14:43
    Jamie Attwood
    0

    Super old question, but anyone still on 7 that runs into this issue as I just did on an old instance - just explicitly cast your values to string instead of using var. I think when dynamic runs into ints it is not casting them correctly. Simply casting to string to match your property's expected type will allow you to continue to use .SetValue().

    Cheers,'

    Jamie

Please Sign in or register to post replies

Write your reply to:

Draft