当前位置: 首页>>代码示例>>C#>>正文


C# Serialization.JavaScriptSerializer类代码示例

本文整理汇总了C#中System.Web.Script.Serialization.JavaScriptSerializer的典型用法代码示例。如果您正苦于以下问题:C# System.Web.Script.Serialization.JavaScriptSerializer类的具体用法?C# System.Web.Script.Serialization.JavaScriptSerializer怎么用?C# System.Web.Script.Serialization.JavaScriptSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


System.Web.Script.Serialization.JavaScriptSerializer类属于命名空间,在下文中一共展示了System.Web.Script.Serialization.JavaScriptSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadFileAjax

        public void UploadFileAjax()
        {
            HttpRequest request = this.Context.Request;

            HttpPostedFile file = request.Files["file"];
            //Save the file appropriately.
            //file.SaveAs(...);

            string msg = "File Name: " + file.FileName;
            msg += "<br />First Name: " + request["first-name"];
            msg += "<br />Country: " + request["country_Value"];

            var o = new { success = true, msg = msg };
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            HttpContext context = this.Context;
            HttpResponse response = context.Response;

            context.Response.ContentType = "text/html";

            string s = serializer.Serialize(o);
            byte[] b = response.ContentEncoding.GetBytes(s);
            response.AddHeader("Content-Length", b.Length.ToString());
            response.BinaryWrite(b);

            try
            {
                this.Context.Response.Flush();
                this.Context.Response.Close();
            }
            catch (Exception) { }
        }
开发者ID:mex868,项目名称:Nissi.Solution,代码行数:32,代码来源:WebService.cs

示例2: GetMemberInformation

        internal SubscriberInformation GetMemberInformation(string memberId)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(apiUri + "/MemberInformation/GetMemberInformation?memberId=" + memberId);
            req.ContentType = "application/json";
            req.Method = "Get";
            req.AllowAutoRedirect = false;
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            String output = RespsoneToString(resp);
            try
            {
                if (output == "null" || string.IsNullOrEmpty(output))
                {
                    return null;
                }
                else
                {
                    System.Web.Script.Serialization.JavaScriptSerializer jser = new System.Web.Script.Serialization.JavaScriptSerializer();
                    object obj = jser.Deserialize(output, typeof(SubscriberInformation));
                    SubscriberInformation result = (SubscriberInformation)obj;
                    return result;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:osaamadasun,项目名称:HRI-Umbraco,代码行数:28,代码来源:MemberInformationService.cs

示例3: Delete

        public void Delete(string uri, string endpoint)
        {
            JObject responseObject = null;
            IdentityManager identityManager = new IdentityManager(this._identity);
            var authData = identityManager.GetAuthData(endpoint);

            string requestUrl = authData.Endpoint + uri;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            request.Method = "DELETE";
            request.Headers.Add("X-Auth-Token", authData.AuthToken);
            request.ContentType = "application/json";
            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            HttpStatusCode statusCode;
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException ex)
            {
                response = (HttpWebResponse)ex.Response;
            }
            statusCode = response.StatusCode;
            if (statusCode.Equals(HttpStatusCode.OK))
            {
            }
        }
开发者ID:hhgzju,项目名称:dotnet-openstack-api,代码行数:27,代码来源:RequestManager.cs

示例4: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/plain";
            //就是将所有的User中的信息添加到主表中 Id, LoginName, Password, Phone, Email, UserState

            List<shaoqi.Model.Comment> list = comBll.GetModelList(" ");
            List<shaoqi.Model.CommentTwo> listTwo = new List<shaoqi.Model.CommentTwo>();
            for (int i = 0; i < list.Count; i++)
            {
                shaoqi.Model.CommentTwo model = new shaoqi.Model.CommentTwo();
                model.Id = list[i].Id;
                model.CommentContext = list[i].ComContent;
                model.UserName = list[i].UserId.LoginName;
                model.CartoonName = list[i].CartoonId.CartoonName;
                model.AddTime = list[i].AddTime;
                listTwo.Add(model);
            }
            System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();

            //还要查出有多少条记录
            string sqlc = "select count(*) from Comment";
            int count = comBll.GetinfoCount(sqlc);

            var info = new { total = count, rows = listTwo };

            string allinfo = json.Serialize(info);

            context.Response.Write(allinfo);
        }
开发者ID:shaoqiming,项目名称:GitHupProject,代码行数:30,代码来源:GetCommentInfo.ashx.cs

示例5: Query

        public string Query(string ip)
        {
            string value;
            if (Cache.TryGetValue(ip, out value))
                return value;

            var client = new WebClient();
            var json = client.DownloadString("http://172.30.0.164:8081/MobiWebService.svc/json/GetCountryISOCode?ip=" + ip + "&key=RIG8UhzkrSKmy7G1P55QdivGTvrbgJ+13thnE8mjzbo=");
            try {
                dynamic res = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<dynamic>(json);
                var country = res["GetCountryISOCodeResult"] as string;
                if (!string.IsNullOrEmpty(country))
                {
                    if (1 == country.Length)
                        country += "-";
                    value = country.ToLower();
                    Cache[ip] = value;
                    return value;
                }
                return null;

            } catch(Exception ex)
            {
                // eat it!
                return null;
            }
        }
开发者ID:homam,项目名称:macademy-stats,代码行数:27,代码来源:UpdateMobiSpyEventsController.cs

示例6: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();

            try
            {
                NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;
                context.Response.ContentType = "text/plain";

                string empStr = context.Request.Form["Employee"];
                if (string.IsNullOrEmpty(empStr))
                {
                    context.Response.Write("员工信息不能为空");
                    context.Response.End();
                }

                string accountStr = context.Request.Form["account"];
                if (string.IsNullOrEmpty(empStr))
                {
                    context.Response.Write("员工账号密码信息不能为空");
                    context.Response.End();
                }

                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                NFMT.User.Model.Employee emp = serializer.Deserialize<NFMT.User.Model.Employee>(empStr);
                NFMT.User.Model.Account account = serializer.Deserialize<NFMT.User.Model.Account>(accountStr);

                if (emp.DeptId <= 0)
                {
                    context.Response.Write("未选择部门");
                    context.Response.End();
                }

                if (string.IsNullOrEmpty(emp.EmpCode))
                {
                    context.Response.Write("未填写员工编号");
                    context.Response.End();
                }

                if (string.IsNullOrEmpty(emp.Name))
                {
                    context.Response.Write("员工名称不能为空");
                    context.Response.End();
                }

                NFMT.User.BLL.EmployeeBLL empBLL = new NFMT.User.BLL.EmployeeBLL();
                result = empBLL.CreateHandler(user, emp, account);

                if (result.ResultStatus == 0)
                    result.Message = "员工新增成功";

            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.ResultStatus = -1;
            }

            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
        }
开发者ID:weiliji,项目名称:NFMT,代码行数:60,代码来源:EmpCreateHandler.ashx.cs

示例7: DragDropPayload

 /// <summary>
 /// Constructor: set members
 /// </summary>
 public DragDropPayload(Constants.operations operation, string name, string guid)
 {
     _operation = operation;
     RpcName = name;
     RpcGuid = guid;
     _jss = new System.Web.Script.Serialization.JavaScriptSerializer();
 }
开发者ID:archvision,项目名称:IPC_Driver,代码行数:10,代码来源:DragDropPayload.cs

示例8: Get

        //public HttpResponseMessage<JsonPReturn> Get(int id, string callback)
        // Changed for Web Api RC
        // GET /api/values/5
        public string Get()
        {
            var _response = new JsonResponseMessage();
            var jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            _response.IsSucess = true;
            _response.Message = string.Empty;
            _response.CallBack = string.Empty;
            _response.ResponseData = "This is a test";

            //context.Response.Write(jSearializer.Serialize(_response));
            // return Request.CreateResponse(HttpStatusCode.Created, "{'id':'" + id.ToString(CultureInfo.InvariantCulture) + "','data':'Hello JSONP'}");

            //var ret =
            //    new HttpResponseMessage<JsonPReturn>(
            //        new JsonPReturn
            //            {
            //                CallbackName = callback,
            //                Json = "{'id':'" + id.ToString(CultureInfo.InvariantCulture) + "','data':'Hello JSONP'}"
            //            });

            //ret.Content.Headers.ContentType = new MediaTypeHeaderValue("application/javascript");
            //return ret;
            return jSearializer.Serialize(_response);
        }
开发者ID:chadit,项目名称:ChlodnyWebApi,代码行数:28,代码来源:ValuesController.cs

示例9: attemptLogIn

        public async Task attemptLogIn()
        {
            if (username == "Username" || password == "1234567")
            {
                return;
            }
            Dictionary<String, String> attrs = new Dictionary<string, string>();
            attrs["password"] = password;
            attrs["username"] = username;
            string api_sig = signMethod("auth.getMobileSession", attrs);
            string requestURL = "https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession&username=" + username +
                "&password=" + password +
                "&api_key=" + API_KEY + "&api_sig=" + api_sig +
                "&format=json";

            string auth_response = await fetchURL(requestURL);
            
            if (auth_response == "")
            {
                user_key = null;
                return;
            }

            AuthenticationResponse auth = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<AuthenticationResponse>(auth_response);
            user_key = auth.session.key;
            return;
        }
开发者ID:genti-jokker,项目名称:Google-Play-Music-Desktop-Player-UNOFFICIAL-,代码行数:27,代码来源:LastFM.Intergration.cs

示例10: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/plain";
            //就是将所有的User中的信息添加到主表中 Id, LoginName, Password, Phone, Email, UserState

            List<shaoqi.Model.Announce> list = annBll.GetModelList(" ");
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].AnnContent.Length > 200)
                {
                    list[i].AnnContent = list[i].AnnContent.Substring(0, 200);
                }

                list[i].adminName = adminBll.GetModel(Convert.ToInt32(list[i].AdminId)).LoginName;
            }
            System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();

            //还要查出有多少条记录
            string sqlc = "select count(*) from Announce";
            int count = annBll.GetinfoCount(sqlc);

            var info = new { total = count, rows = list };

            string allinfo = json.Serialize(info);

            context.Response.Write(allinfo);
        }
开发者ID:shaoqiming,项目名称:GitHupProject,代码行数:28,代码来源:GetAllAnnounce.ashx.cs

示例11: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();
            context.Response.ContentType = "text/plain";
            NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;

            string documentStr = context.Request.Form["document"];
            string docStocksStr = context.Request.Form["docStocks"];
            string isSubmitAuditStr = context.Request.Form["IsSubmitAudit"];

            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            NFMT.Document.Model.Document document = serializer.Deserialize<NFMT.Document.Model.Document>(documentStr);
            List<NFMT.Document.Model.DocumentStock> docStocks = serializer.Deserialize<List<NFMT.Document.Model.DocumentStock>>(docStocksStr);

            bool isSubmitAudit = false;
            if (string.IsNullOrEmpty(isSubmitAuditStr) || !bool.TryParse(isSubmitAuditStr, out isSubmitAudit))
                isSubmitAudit = false;

            NFMT.Document.BLL.DocumentBLL bll = new NFMT.Document.BLL.DocumentBLL();
            result = bll.Create(user, document, docStocks, isSubmitAudit);

            if (result.ResultStatus == 0)
                result.Message = "制单新增成功";

            string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(result);
            context.Response.Write(jsonStr);
        }
开发者ID:weiliji,项目名称:NFMT,代码行数:28,代码来源:DocumentCreateHandler.ashx.cs

示例12: ConvertDataTabletoString

 public string ConvertDataTabletoString(string bib)
 {
     DataTable dt = new DataTable();
     using (SqlConnection con = new SqlConnection("Data Source=184.168.194.70;Initial Catalog=ittitudeworks;User ID=rakesh123; [email protected]; Trusted_Connection=False"))
     {
         using (SqlCommand cmd = new SqlCommand("select * from all_triathlon_timing where BIBNumber='" + bib.ToString() + "'", con))
         {
             con.Open();
             SqlDataAdapter da = new SqlDataAdapter(cmd);
             da.Fill(dt);
             System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
             List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
             Dictionary<string, object> row;
             foreach (DataRow dr in dt.Rows)
             {
                 row = new Dictionary<string, object>();
                 foreach (DataColumn col in dt.Columns)
                 {
                     row.Add(col.ColumnName, dr[col]);
                 }
                 rows.Add(row);
             }
             return serializer.Serialize(rows);
         }
     }
 }
开发者ID:rakeshctc,项目名称:ctcpg,代码行数:26,代码来源:data.aspx.cs

示例13: Parse

        private static Dictionary<string, List<Dictionary<string, object>>> Parse(string jsonString)
        {
            if (jsonString == null || jsonString == String.Empty)
                throw new ArgumentNullException("jsonString");

            Dictionary<string, ArrayList> jsonContent = null;
            try
            {
                jsonContent = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Dictionary<string, ArrayList>>(jsonString);
            }
            catch
            {
                throw new InvalidCastException("jsonString");
            }

            Dictionary<string, List<Dictionary<string, object>>> result = new Dictionary<string, List<Dictionary<string, object>>>();

            foreach (KeyValuePair<string, ArrayList> arrayElement in jsonContent)
            {
                List<Dictionary<string, object>> temp = new List<Dictionary<string, object>>();
                foreach (object obj in arrayElement.Value)
                {
                    temp.Add((Dictionary<string, object>)(obj));
                }

                result.Add(arrayElement.Key, temp);
            }

            return result;
        }         
开发者ID:Dmitry-Karnitsky,项目名称:Epam_ASP.NET_Courses,代码行数:30,代码来源:JsonHelper.cs

示例14: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();
            context.Response.ContentType = "text/plain";
            NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;

            string orderStr = context.Request.Form["order"];
            string orderStockInvoiceStr = context.Request.Form["orderStockInvoice"];
            string orderDetailStr = context.Request.Form["orderDetail"];
            string isSubmitAuditStr = context.Request.Form["IsSubmitAudit"];

            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            NFMT.Document.Model.DocumentOrder order = serializer.Deserialize<NFMT.Document.Model.DocumentOrder>(orderStr);
            List<NFMT.Document.Model.OrderStockInvoice> stockInvoices = serializer.Deserialize<List<NFMT.Document.Model.OrderStockInvoice>>(orderStockInvoiceStr);
            NFMT.Document.Model.DocumentOrderDetail detail = serializer.Deserialize<NFMT.Document.Model.DocumentOrderDetail>(orderDetailStr);

            bool isSubmitAudit = false;
            if (string.IsNullOrEmpty(isSubmitAuditStr) || !bool.TryParse(isSubmitAuditStr, out isSubmitAudit))
                isSubmitAudit = false;

            NFMT.Document.BLL.DocumentOrderBLL bll = new NFMT.Document.BLL.DocumentOrderBLL();
            result = bll.Create(user, order, stockInvoices, detail, isSubmitAudit);

            if (result.ResultStatus == 0)
                result.Message = "制单指令新增成功";

            string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(result);
            context.Response.Write(jsonStr);
        }
开发者ID:weiliji,项目名称:NFMT,代码行数:30,代码来源:OrderCreateHandler.ashx.cs

示例15: getSLDuAn_DaDauTu

        public static string getSLDuAn_DaDauTu( List<EntityDuAn> duan)
        {
            string[] mang = new string[] { "#FF99CC", "#CC99CC", "#9999CC", "#6699CC", "#0099CC", "#FF66CC", "#CC99CC", "#6699CC", "#0099CC", "#3366CC", "#00EE00", "#008800", "#002200", "#000044", "#DDC488", "#ECAB53", "#008080", "#FFCC99", "#FFD700", "#9932CC", "#8A2BE2", "#C71585", "#800080", "#FFBF00", "#9966CC", "#7FFFD4", "#007FFF", "#3D2B1F", "	#0000FF", "#DE3163", "#7FFF00", "#50C878", "#DF73FF", "#4B0082", "#FFFF00", "#008080", "#660099", "#FFE5B4" };
            dbFirstStepDataContext db = new dbFirstStepDataContext();
            List<BanDoModel> list = new List<BanDoModel>  ();
            var danhmuc  =  db.EntityDanhMucs.Where(g => g.IdRoot ==1).ToList();
            Random rd = new Random();
            int vt = rd.Next(mang.Count()-danhmuc.Count());
            int i = -1;
            foreach(var item in danhmuc)
            {
                i++;
                BanDoModel bando = new BanDoModel ();
                int sl = duan == null ? 0 : duan.Where(g => g.IdDanhMuc == item.Id).ToList().Count();
                bando.value = 1;
                if (sl > 0)
                {
                    bando.color = mang[vt+i];

                }
                else bando.color = "#f5f5f5";

             //   bando.color = sl > 0 ? "#14c3be" : "#f5f5f5";
                bando.highlight = "#FF5A5E";
                bando.label = item.TenDM.ToString()+"("+sl+")";
                list.Add(bando);
            }

            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string sJSON = oSerializer.Serialize(list);
            return sJSON;
        }
开发者ID:centaurustech,项目名称:khainguyen-FirstStep,代码行数:32,代码来源:BanDoModel.cs


注:本文中的System.Web.Script.Serialization.JavaScriptSerializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。