0

我有这个模型用于 MVC WEB API 控制器。与此模型结构匹配的相应 JSON 是什么?

namespace CarEvaluator.Models
{
    [DataContract]
    public class Record
    {
        [DataMember]
        public List<Boolean> CHits { get; set; }

        [DataMember]
        public List<Boolean> MHits { get; set; }
    }
}




public void Post(Record record)
{

}
4

1 回答 1

1

结构:

{"CHits":[true,false],"MHits":[true,false]}

例子:

var postObject = new Object();

// Initialize CHits and MHits as arrays
postObject.CHits = [];
postObject.MHits = [];

// push some items into the arrays
postObject.CHits.push(true);
postObject.CHits.push(false);
postObject.MHits.push(true);
postObject.MHits.push(false);

// serialize data to post
// this is what you set as data property in for instance jquery ajax
$.ajax({
    //other params, content type etc
    type: 'POST',
    data: JSON.stringify(postObject),
    ...
    });

如果您的参数为空,您应该尝试添加 [FromBody] 属性并使用 httppost 装饰方法

[HttpPost]
public void Post([FromBody]Record record)
{

}
于 2013-10-28T18:45:51.813 回答