在web API中,我遇到了来自客户端的情况,请求正文如下
{ "device-id":100101,"device-name": "Samsung 001"}
my model class
public class DeviceDesc
{
public string device_id {get;set;}
public string device_name {get;set;}
}
So the values are not binding to the properties. In c# we cannot declare properties with " - " symbol. So how I can do this in web api. the request body cannot be changed bcoz the JSON is generated by some third-party app. Please, any solution for this.谢谢Saroj
发布于 2017-01-25 15:19:15
您可以在JSON.NET中使用[JsonProperty(PropertyName="JSON_NAME"]。例如:
public class DeviceDesc
{
[JsonProperty(PropertyName="device-id"]
public string device_id {get;set;}
[JsonProperty(PropertyName="device-name"]
public string device_name {get;set;}
}https://stackoverflow.com/questions/41845526
复制相似问题