System.Text.Json Deserialize nested object from API call - Data is wrapped in parent JSON property

后端 未结 4 1730
春和景丽
春和景丽 2021-01-22 16:40

I have an API JSON response that wraps the data content in a data property, which looks like this:

{ 
   \"d         


        
4条回答
  •  萌比男神i
    2021-01-22 17:22

    You need to make one another class. That is given below

    Public class UserData
    {
        public User data { get; set; }; 
    }
    

    Now you can Deserialize data using new class called UserData like below

    UserData account = JsonSerializer.Deserialize(response.Content, options);
    

提交回复
热议问题