JSON.NET deserialize/serialize JsonProperty JsonObject

前端 未结 2 1432
名媛妹妹
名媛妹妹 2021-01-13 01:35

I have a question for deserialize/serialize with the Newtonsoft JSON.NET library:

I receive this json :

 {
    \"customerName\" : \"Lorem\",
    \"id         


        
相关标签:
2条回答
  • 2021-01-13 02:04

    You need to make custom type for "attribute" like:

        public class Attribute {
    
            [JsonProperty(PropertyName = "nbrOfUse")]
            public int _nbrOfUse { get; set; }
            [JsonProperty(PropertyName = "streetType")]
            [Display(Name = "lastUse", ResourceType = typeof(AccountModels))]
            public string _lastUse { get; set; }
    
        }
    

    And make an Object of Attribute class in your Address class.

    0 讨论(0)
  • 2021-01-13 02:11

    One possible solution you could use, which might look a bit hacky, would be to manipulate the JSON string before parsing it, using a regex for example.

    You would identify and replace

    "attribute" : {
       "nbrOfUse" : 1,
       "lastUse" : "2013-01-03T09:57:28-0500"
     }
    

    with

    "lastUse" : "2013-01-03T09:57:28-0500"
    

    Then, your serializer would identify a DateTime? property named "lastUsed"

    0 讨论(0)
提交回复
热议问题