javascriptserializer

JavaScriptSerializer UTC DateTime issues

自作多情 提交于 2019-11-26 08:26:17
问题 Our client wanted to show the date and time values in the browser exactly as they are in the database, and we are storing them as UTC in the database. At first we had some problems with the serialization and Javascript side. The DateTime values got shifted twice - at first to match the local time zone of the machine and then to match the time zone in the browser. We fixed it by adding a custom Converter to the JavaScriptSerializer. We marked the DateTime to be of DateTimeKind.Utc in the

How to not serialize the __type property on JSON objects

≡放荡痞女 提交于 2019-11-26 07:29:47
问题 Every object I return from a WebMethod of a ScriptService is wrapped into a JSON object with the data in a property named d . That\'s ok. But I don\'t want the additional __type property to be served to the client, since I do manual processing with jQuery. Is it possible? 回答1: I found that if I make the default constructor of my class that my webmethod returns anything other than public it will not serialize the __type:ClassName portion. You may want to declare your default constructor

Return JSON from ASMX web service, without XML wrapper?

为君一笑 提交于 2019-11-26 06:48:44
问题 I need to get Json data from a C# web service. I know there are several questions based on this, trust me I have read through quite a few but only to confuse me further. This is what I have done : In my web service I have included : [System.Web.Script.Services.ScriptService] for the class & [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)] for the method I have also used a JavaScriptSerializer() to convert my data to a string I am calling this service using $.getJSON()

How to get JSON response from a 3.5 asmx web service

元气小坏坏 提交于 2019-11-26 06:44:18
问题 I have the following method: using System.Web.Services; using System.Web.Script.Services; using System.Web.Script.Serialization; using Newtonsoft.Json; using System.Collections; [WebService(Namespace = \"http://tempuri.org/\")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] //[System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] // [System.Web.Script.Services.ScriptService] public class Tripadvisor : System.Web.Services.WebService { public

JavaScriptSerializer.Deserialize - how to change field names

你说的曾经没有我的故事 提交于 2019-11-26 01:39:31
问题 Summary : How do I map a field name in JSON data to a field name of a .Net object when using JavaScriptSerializer.Deserialize ? Longer version : I have the following JSON data coming to me from a server API (Not coded in .Net) {\"user_id\":1234, \"detail_level\":\"low\"} I have the following C# object for it: [Serializable] public class DataObject { [XmlElement(\"user_id\")] public int UserId { get; set; } [XmlElement(\"detail_level\")] public DetailLevel DetailLevel { get; set; } } Where

How do I get formatted JSON in .NET using C#?

北慕城南 提交于 2019-11-26 00:42:19
问题 I am using .NET JSON parser and would like to serialize my config file so it is readable. So instead of: {\"blah\":\"v\", \"blah2\":\"v2\"} I would like something nicer like: { \"blah\":\"v\", \"blah2\":\"v2\" } My code is something like this: using System.Web.Script.Serialization; var ser = new JavaScriptSerializer(); configSz = ser.Serialize(config); using (var f = (TextWriter)File.CreateText(configFn)) { f.WriteLine(configSz); f.Close(); } 回答1: You are going to have a hard time

JavaScriptSerializer - JSON serialization of enum as string

自闭症网瘾萝莉.ら 提交于 2019-11-25 23:59:42
问题 I have a class that contains an enum property, and upon serializing the object using JavaScriptSerializer , my json result contains the integer value of the enumeration rather than its string \"name\". Is there a way to get the enum as a string in my json without having to create a custom JavaScriptConverter ? Perhaps there\'s an attribute that I could decorate the enum definition, or object property, with? As an example: enum Gender { Male, Female } class Person { int Age { get; set; }