Copied to clipboard

Flag this post as spam?

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


  • Robert Dougan 48 posts 154 karma points
    Jul 29, 2015 @ 09:17
    Robert Dougan
    0

    Saving JSON to Xml PrefetchList Picker

    Hi,

    I'm using the JSON save format for a member data type based on the Xml PrefetchList Picker nuPicker type.

    In my code I use JSON.Net to deserialize the picker's value to a list of my custom type:

    List<myType> fromPicker = JsonConvert.DeserializeObject<List<myType>>(pickerProperty.Value.ToString());
    

    I then add a new object to my list:

    fromPicker.Add(new myType(){ Key = "test", Label = "test" });
    

    And then serialize the list to save it back to the picker property:

    myMember.SetValue("propName", JsonConvert.SerializeObject(fromPicker));
    

    This does indeed save the value, and if I access the picker value elsewhere, the new object I've added will be shown, but it doesn't reflect in the property value in the backoffice. So if the node is saved in the backoffice (in my case the node is a member), it overwrites the value I have set in my code.

    The question is, how do I correctly save values to an Xml PrefetchList Picker from code?

    Thanks, Rob

  • Robert Dougan 48 posts 154 karma points
    Aug 04, 2015 @ 10:48
    Robert Dougan
    101

    I solved my own problem if anyone is interested.

    The myType class I had created needed to use lowercase property names, i.e. "key" and "label", rather than uppercase.

    This will then create a JSON string that matches the format produced when the member is saved from the back office.

    Rob

Please Sign in or register to post replies

Write your reply to:

Draft