c# - Json .NET Serialization - change the property value -


good day!

i using newtonsoft json serializer through following code:

        private string serializeandignoreemail(usermembership obj)         {             var json = jsonconvert.serializeobject(obj, formatting.indented,                 new jsonserializersettings() { contractresolver = new documentidcontractresolver() });             return json;         }         private class documentidcontractresolver : camelcasepropertynamescontractresolver         {             protected override list<memberinfo> getserializablemembers(type objecttype)             {                 return base.getserializablemembers(objecttype).where(o => o.name != "email").tolist();             }         } 

everytime need serialize object call 'serializeandignoreemail' method. want replace content of each property it's encrypted version , don't know this.

my guess override method in 'documentidcontractresolver', there many createblahblahblah ones, find hard work them.

is right approach, continue modifying contractresolver or should try else?

thank you!

calling serializeobject 2 things: create tree of json tokens based on object specify, , serialize string containing json.

your best bet 2 steps separately: first ask json.net provide tree of json tokens, modify values, serialize them json.

from top of head:

namespace jsonencryptiontest {     class program     {         static void main(string[] args)         {             var obj = new                 {                     = "some name",                     subject = "a subject",                     content = "a content"                 };              var jsonobject = jobject.fromobject(obj);              // modify values. doing here amuse you.            var property = jsonobject.property("content");            var value = (string) property.value;            property.value = value.tolower();              var json = jsonobject.tostring();              console.writeline(json);         }     } } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -