Get Raw json string in Newtonsoft.Json Library

后端 未结 6 1188
别那么骄傲
别那么骄傲 2020-12-11 01:42

I have json like this

{
    \"name\": \"somenameofevent\",
    \"type\": \"event\",
    \"data\": {
        \"object\": {
            \"age\": \"18\",
               


        
6条回答
  •  借酒劲吻你
    2020-12-11 02:31

    You don't need to write any converters, just use the JRaw type as follows:

    public class SomeData
    {
        [JsonProperty("object")]
        public JRaw SomeObject { get; set;}
        [JsonProperty("dsct")]
        public JRaw SomeDesct { get; set; }
    }
    

    Then you can access the raw value by checking the .Value property:

    var rawJsonDesct = (string)data.SomeDesct.Value;
    

    If you want to retain the string signature, just serialize the JSON to a hidden property and have the string conversion in the accessor call instead.

提交回复
热议问题