Read value from dynamic property from json payload

前端 未结 2 915
情话喂你
情话喂你 2021-01-23 12:22

I have a simple model that I used as a request payload

public class CommandRequest
{
    public CommandType Type { get; set; }
    public dynamic Attributes { get         


        
2条回答
  •  孤街浪徒
    2021-01-23 13:06

    1. You can use the GetProperty method on the JsonElement to get the property you desire.
    2. You can deserialize with JsonConvert.Deseralize("jsonpayload") to the model of Attributes and get Name directly with the "." notation.
    3. You can deserialize to Dictionary and get the property name as Dict["Name"].

提交回复
热议问题