WebAPI

  1. [HttpPost]
  2. public HttpResponseMessage test([FromBody]List<Class1> list)
  3. {
  4. return Common.JsonHelper.ToJson(null);
  5. }

Class1

  1. [Serializable]
  2. public class Class1
  3. {
  4. public int ID { get; set; }
  5. public string Value { get; set; }
  6. }

POST RAW

  1. POST http://127.0.0.1:8021/HISApi/bgService.Service/Ylxm/test HTTP/1.1
  2. cache-control: no-cache
  3. Postman-Token: 70ccc912-0737-43ff-94db-5fefdcbcb067
  4. Accept: application/json, text/javascript, */*; q=0.01
  5. Content-Type: application/json
  6. User-Agent: PostmanRuntime/3.0.9
  7. Host: 127.0.0.1:8021
  8. accept-encoding: gzip, deflate
  9. content-length: 30
  10. Connection: keep-alive
  11. [{"ID":10,"Value":" 张三 "}]

接收不到对象值

Serializable造成Post接收不到值 - 图1

解决办法一:删除[Serializable]标记

解决办法二:把实体标记加上 [DataContract] ;属性上加上[DataMember] 标记

  1. [Serializable]
  2. [DataContract]
  3. public class Class1
  4. {
  5. [DataMember]
  6. public int ID { get; set; }
  7. [DataMember]
  8. public string Value { get; set; }
  9. }