WebAPI:
[HttpPost] public HttpResponseMessage test([FromBody]List<Class1> list) { return Common.JsonHelper.ToJson(null); }
Class1
[Serializable] public class Class1 { public int ID { get; set; } public string Value { get; set; } }
POST RAW
POST http://127.0.0.1:8021/HISApi/bgService.Service/Ylxm/test HTTP/1.1 cache-control: no-cache Postman-Token: 70ccc912-0737-43ff-94db-5fefdcbcb067 Accept: application/json, text/javascript, */*; q=0.01 Content-Type: application/json User-Agent: PostmanRuntime/3.0.9 Host: 127.0.0.1:8021 accept-encoding: gzip, deflate content-length: 30 Connection: keep-alive [{"ID":10,"Value":" 张三 "}]
接收不到对象值:
解决办法一:删除[Serializable]标记
解决办法二:把实体标记加上 [DataContract] ;属性上加上[DataMember] 标记
[Serializable] [DataContract] public class Class1 { [DataMember] public int ID { get; set; } [DataMember] public string Value { get; set; } }