JSON.NET: Serialize json string property into json object

后端 未结 3 1954
北海茫月
北海茫月 2020-12-15 19:10

Is it possible to tell JSON.NET I have a string with JSON data? E.g. I have a class like this:

public class Foo
{
    public int Id;
    public string RawDat         


        
3条回答
  •  独厮守ぢ
    2020-12-15 19:27

    You can use another property to deserialize the object property json.

    public class Foo
    {
        public int Id;
        public string RawData;
        private object thisObject;
        public object ThisObject 
        {
            get
            {
                return thisObject ?? (thisObject = JsonConvert.DeserializeObject(RawData));
            }
        }        
    }
    
        

    提交回复
    热议问题