首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >asp.net web api :将请求主体值绑定到模型类

asp.net web api :将请求主体值绑定到模型类
EN

Stack Overflow用户
提问于 2017-01-25 15:13:35
回答 1查看 213关注 0票数 0

在web API中,我遇到了来自客户端的情况,请求正文如下

代码语言:javascript
复制
{ "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

EN

回答 1

Stack Overflow用户

发布于 2017-01-25 15:19:15

您可以在JSON.NET中使用[JsonProperty(PropertyName="JSON_NAME"]。例如:

代码语言:javascript
复制
public class DeviceDesc
{
    [JsonProperty(PropertyName="device-id"]
    public string device_id {get;set;}
    [JsonProperty(PropertyName="device-name"]
    public string device_name {get;set;}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41845526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档