c# - Splitting a JSON key based on regex to store in multiple variables -


{"key":"abc/1"} 

i want store value in 2 fields instead of one. can following.

[jsonproperty(propertyname = "key", required = required.always)] public string value { get; set; } 

however, want have 2 fields use jsonpropertyto serialize , deserialize them combined string. example, if define following fields:

public string valuescope { get; set; } public int valueid { get; set; } 

i want use jsonproperty or other tag populate fields while deserializing. possible that, i.e. populate valuescope "abc" , valueid 1 ?

yes, can implement get , set of 2 properties manipulate underlying jsonproperty.

here's quick example of how might go (warning: wrote out in notepad, please excuse typos).

public string valuescope {         {         var values = (this.value ?? "").split('/');         if (values.length == 2)             return values[0];         else             return null;     }     set     {         this.value = (value ?? "") + "/" + this.valueid.tostring();     } }  public int valueid {         {         int currentvalue;         var values = (this.value ?? "").split('/');         if (values.length == 2 && int.tryparse(values[1], out currentvalue))             return currentvalue;         else             return default(int);     }     set     {         this.value = (this.valuescope ?? "") + "/" + value.tostring();     } } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -