Deserializing just a single node of a JSON response

后端 未结 2 790
慢半拍i
慢半拍i 2021-01-25 15:01

I have a json response like

{
  \"appStatus\":{
    \"status\":true
  },
  \"lastSyncDate\":\"06-07-2013 13.54.27\",
  \"configResponse\":{
    \"status\":{
            


        
相关标签:
2条回答
  • 2021-01-25 15:16

    i have only use this method and it worked.

     await JsonConvert.DeserializeObjectAsync<ConfigResponse>(jsontoobject, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
    
    0 讨论(0)
  • 2021-01-25 15:36

    You can parse JSON string into JObject, get sub-object "configResponse", then deserialize it into ConfigResponse. It's one line of code:

    JObject.Parse("{...}")["configResponse"].ToObject<ConfigResponse>()
    

    If you need a custom serializer to set deserialization options, you can pass it to ToObject<T>() method.

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