[RoutePrefix("Api")]json
public class UploadController:BaseApiControllerpost
{this
[HttpPost]string
[Route("Upload")]io
public IHttpActionResult Upload()class
{coding
try{request
//接收post傳入的數據im
var request=System.Web.HttpContext.Current.Request;數據
byte[] requestData=new byte[request.InputStream.Length];
request.InputStream.Read(requestData,0,(int),request.InputStream.Length);
var jsonData=Encoding.UTF8.GetString(requestData);
string JsonData=jsonData.TrimStart('"').TrimEnd('"').Replace(@"\","");
dynamic m=JsonData.ToObject<dynamic>();
//實體化後直接賦值
string MeterNo=m.MeterNo;
string UserCode=m.UserCode;
}
catch(Exception ex){
throw ex;
}
}
public static T ToObject<T>(this string Json)
{
return Json==null?default(T):JsonConvert.DeserializeObject<T>(Json);
}
}