zoukankan      html  css  js  c++  java
  • c# 动态获取http通过post传来的json数据

    //获取http通过post传来的json数据

    using Newtonsoft.Json;

    public HttpResponseMessage Query()

    {

    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);

    //转化成json数据

    dynamic m=jsonData.ToObject<dynamic>();

    string MeterAddr=string.Empty;

    string StartTime=string.Empty;

    string EndTime=string.Empty;

    //获取json数据的字段值

    MeterAddr=m.meterid;

    StartTime=m.StartTime;

    EndTime=m.EndTime;

    }

    //返回json数据

    public static T ToObject<T>(this string Json)

    {

    return Json==null?default(T):JsonConvert.DeserializeObject<T>(Json)

    }

  • 相关阅读:
    nodejs
    socket.io
    how to develop mobile web
    nodejs
    GitHub
    angularJS vs backbone
    AngularJS
    oracle 数据库中数据导出到excel
    cocos2d-x中的二段构造模式
    HDOJ 4975 A simple Gaussian elimination problem.
  • 原文地址:https://www.cnblogs.com/huodige/p/11209046.html
Copyright © 2011-2022 走看看