C# post请求,Json转换实体类
public GetFloorBuildingResult GetFloorBuilding([FromBody]GetFloorBuildingModels model) { string dd = model.Fatherid; string serviceAddress = "http://public.data.test.facehm.cn/api/PropertyData/GetFloorBuilding"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress); request.Method = "POST"; request.ContentType = "application/json"; string strContent = @"{ ""Fatherid"": " + "'" + dd + "'" + "}"; using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream())) { dataStream.Write(strContent); dataStream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string encoding = response.ContentEncoding; if (encoding == null || encoding.Length < 1) { encoding = "UTF-8"; //默认编码 } StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding)); string retString = reader.ReadToEnd(); //JObject jo = JObject.Parse(retString); //解析josn GetFloorBuildingResult jo1 = JsonConvert.DeserializeObject<GetFloorBuildingResult>(retString); return jo1; }