javascriptserializer

“<” character in JSON data is serialized to \\u003c

六眼飞鱼酱① 提交于 2019-11-28 13:45:58
I have a JSON object where the value of one element is a string. In this string there are the characters "<RPC>" . I take this entire JSON object and in my ASP.NET server code, I perform the following to take the object named rpc_response and add it to the data in a POST response: var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); HttpContext.Current.Response.AddHeader("Pragma", "no-cache"); HttpContext.Current.Response.AddHeader("Cache-Control", "private, no-cache"); HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=\"files.json\"");

JavaScriptSerializer not deserializing DateTime/TimeSpan Properly

佐手、 提交于 2019-11-28 13:08:36
Having a problem where DateTime/TimeSpan doesn't seem to deserialize properly with JavaScriptSerializer. When I get the Object back after deserializing the TimeSpan is empty and if I use DateTime then the times are all out of whack. Did find this article but it didn't really help me too much. http://www.west-wind.com/weblog/ShowPost.aspx?id=471402 Anyone have any ideas? Should I maybe try the json.net library? public class JsonFilter : ActionFilterAttribute { public string Param { get; set; } public Type JsonDataType { get; set; } public override void OnActionExecuting(ActionExecutingContext

JavaScriptSerializer is subtracting one day from date

蓝咒 提交于 2019-11-28 09:42:50
I am using JavaScriptSerializer for serializing DateTime, but when I deserialize it show one day less from the date it get serialize: Here is test: DateTime startDate=new DateTime(2012,1,20);//set the 20th of January JavaScriptSerializer serializer=new JavaScriptSerializer(); string serializeDate= serializer.Serialize(startDate); DateTime afterDeserialize= serializer.Deserialize<DateTime>(serializeDate);//I get 19th of Jan Assert.Equals(startDate, afterDeserialize); firstly I thougt it because of javascript datetime format but as I know for javascript Month is zero index 0=January , but I am

JavaScriptSerializer with custom Type

我是研究僧i 提交于 2019-11-28 09:16:14
I have a function with a List return type. I'm using this in a JSON-enabled WebService like: [WebMethod(EnableSession = true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<Product> GetProducts(string dummy) /* without a parameter, it will not go through */ { return new x.GetProducts(); } this returns: {"d":[{"__type":"Product","Id":"2316","Name":"Big Something ","Price":"3000","Quantity":"5"}]} I need to use this code in a simple aspx file too, so I created a JavaScriptSerializer: JavaScriptSerializer js = new JavaScriptSerializer(); StringBuilder sb = new StringBuilder();

convert json to c# list of objects

会有一股神秘感。 提交于 2019-11-28 09:14:07
Json string: {"movies":[{"id":"1","title":"Sherlock"},{"id":"2","title":"The Matrix"}]} C# class: public class Movie { public string title { get; set; } } C# converting json to c# list of Movie's: JavaScriptSerializer jss = new JavaScriptSerializer(); List<Movie> movies = jss.Deserialize<List<Movie>>(jsonString); My movies variable is ending up being an empty list with count = 0. Am I missing something? Your c# class mapping doesn't match with json structure. Solution : class MovieCollection { public IEnumerable<Movie> movies { get; set; } } class Movie { public string title { get; set; } }

JavaScriptSerializer - custom property name

做~自己de王妃 提交于 2019-11-28 02:00:07
I am using JavaScriptSerializer to deserialize json data. Everything works pretty well, but my problem is, that one property in json data is named 'base', so I cannot create such property in my C# code. I found that i can manually map values to properties in constructor, but the issue is, that my DTOs have like 200 properties, so I do not want to make this manually and would prefer to find any other solution. I also Tried to use annotations, but this: [JsonProperty("base")] public int baseValue { get; set; } did not help me, value baseValue was set to 0 each time (if you think, that this

How to set formatting with JavaScriptSerializer when JSON serializing?

可紊 提交于 2019-11-27 21:12:16
I am using JavaScriptSerializer for serializing objects to the file to the JSON format. But the result file has no readable formatting. How can I allow formating to get a readable file? It seemed to be that there is no built-in tool for formatting JSON-serializer's output. I suppose the reason why this happened is minimizing of data that we send via network. Are you sure that you need formatted data in code? Or you want to analize JSON just during debugging? There is a lot of online services that provide such functionality: 1 , 2 . Or standalone application: JSON viewer . But if you need

“<” character in JSON data is serialized to \u003c

只愿长相守 提交于 2019-11-27 19:30:19
问题 I have a JSON object where the value of one element is a string. In this string there are the characters "<RPC>" . I take this entire JSON object and in my ASP.NET server code, I perform the following to take the object named rpc_response and add it to the data in a POST response: var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); HttpContext.Current.Response.AddHeader("Pragma", "no-cache"); HttpContext.Current.Response.AddHeader("Cache-Control", "private, no-cache")

From DataTable in C# .NET to JSON

柔情痞子 提交于 2019-11-27 18:12:37
I am pretty new at C# and .NET, but I've made this code to call a stored procedure, and I then want to take the returned DataTable and convert it to JSON. SqlConnection con = new SqlConnection("connection string here"); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand("getDates", con); SqlParameter par = new SqlParameter("@PlaceID", SqlDbType.Int); par.Value = 42; da.SelectCommand = cmd; cmd.Parameters.Add(par); DataSet ds = new DataSet(); DataTable dt = new DataTable(); con.Open(); try{ cmd.CommandType = CommandType.StoredProcedure; da.Fill(ds); } My question then is

JSON Maximum length problem with ASP.NET

别等时光非礼了梦想. 提交于 2019-11-27 18:11:21
问题 I am creating a asp.net 2.0 webservice which give json as output and there's a very large, can't be break down, dataset which exceed the max length limit I have search on the internet, and there's solution on .net 3.5 & 4, but not 2.0. Can any tell me how can I increase the JSON legth limit? 回答1: I had this same exact problem. Was getting frustrated seeing 3.5 and 4.0 solutions. Turns out you do the same thing, you just have to add a couple lines to the <ConfigSections> tag in your Web.config