javascriptserializer

Azure time zone and javascriptserializer object

℡╲_俬逩灬. 提交于 2019-12-10 18:17:41
问题 I have a predictions-based app that's up on Windows Azure ( http://ipredikt.com ). From what I can tell Azure's clock is synchronized to the GMT time zone. Here is a problem that I am encountering: Let's say I have a DB field called CreateDate of type DateTime and I set its value to June 10, 2011, 12:30am. when a new prediction is created. If I peek inside the db table the date is correctly set. I don't touch or change this value in any way. However, when I read the value with our API,

Convert type 'System.Dynamic.DynamicObject to System.Collections.IEnumerable

自作多情 提交于 2019-12-10 02:30:19
问题 I'm successfully using the JavaScriptSerializer in MVC3 to de-serialize a json string in to a dynamic object. What I can't figure out is how to cast it to something I can enumerate over. The foreach line of code below is my latest attemt but it errors with: "Cannot implicitly convert type 'System.Dynamic.DynamicObject' to 'System.Collections.IEnumerable'. How can I convert or cast so that I can iterate through the dictionary? public dynamic GetEntities(string entityName, string entityField) {

why does c# JavaScriptSerializer.Serialize return empty square brackets

三世轮回 提交于 2019-12-08 20:47:28
问题 Why does the following code return "[ ]" when it should return "{"id":1999, "title":"hithere"} JavaScriptSerializer serializer = new JavaScriptSerializer(); StringBuilder sbJsonResults = new StringBuilder(); var result = serializer.Serialize(new dg(1999, "hithere")); context.Response.Clear(); context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Cache.SetExpires(DateTime.MinValue); context.Response.Write(result); P.S. the dg class looks like this: public class dg

ASMX webservice - return JSON instead of XML

邮差的信 提交于 2019-12-08 19:53:44
问题 I have a web service that contains one method: [WebMethod] public string Movies() { using (var dataContext = new MovieCollectionDataContext()) { var query = dataContext.Movies.Select(m =>new{m.Title,m.ReleaseDate}).Take(20); var serializer = new JavaScriptSerializer(); return serializer.Serialize(query); } } The method properly serializes the object, but when I view the response in FireBug, it looks like this: <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://tempuri.org/">[{"Title

How to deserialize variable size JSON string with variable names

久未见 提交于 2019-12-08 08:17:34
问题 Deserializing a small, fixed size, fixed structure, with fixed field names, JSON string is easy: Just define a class that contains all the fields (with correct types and names, all known at compile time). Deserializing a variable-size of repeating nested pairs, is somewhat more challenging but can be done with the help of a List<> inside the class. But what do I do when the name of the fields are unknown at compile time? e.g.: { "container":{ "GD01AB491103":{ "field_id1":11, "field_id2":12,

Trouble Serializing To JSON Using JavaScriptSerializer

孤街浪徒 提交于 2019-12-08 07:37:46
问题 I'm having some trouble serializing an object to a JSON string using System.Web.Script.Serialization.JavaScriptSerializer. Whenever I try to do it, my strings are automatically html encoded. Is there a way to prevent this from happening? I'd really like to avoid using an external library if possible (code is for .NET 4). Here's my code: class Program { static void Main(string[] args) { string myHtml = "<div class=\"blueBackground\">This is a really cool div:)</div>"; int someOtherValue = 5;

How to deserialize variable size JSON string with variable names

强颜欢笑 提交于 2019-12-06 22:53:28
Deserializing a small, fixed size, fixed structure, with fixed field names, JSON string is easy: Just define a class that contains all the fields (with correct types and names, all known at compile time). Deserializing a variable-size of repeating nested pairs, is somewhat more challenging but can be done with the help of a List<> inside the class. But what do I do when the name of the fields are unknown at compile time? e.g.: { "container":{ "GD01AB491103":{ "field_id1":11, "field_id2":12, "field_id3":13, "field_id4":"fourteen" }, "DC01AB491103":{ "field_id1":21, "field_id2":22, "field_id3"

Validating JSON before deserializing into C# object

随声附和 提交于 2019-12-06 16:25:47
If a JavaScript object in JSON is not going to deserialize into the C# object I want, how can I interrogate it to provide an error message explaining what is wrong with the input? (Assuming the JSON format is correct, just the data is not valid.) My C# class: (simplified) public class Dependent { public Dependent() { } public string FirstName { get; set; } public DateTime DateOfBirth { get; set; } } Test code to deserialize: string dependents = @"[ { ""FirstName"": ""Kenneth"", ""DateOfBirth"": ""02-08-2013"" }, { ""FirstName"": ""Ronald"", ""DateOfBirth"": ""08-07-2011"" } ]";

String exceeds maxJsonLength with less than 250kb

雨燕双飞 提交于 2019-12-06 08:41:08
问题 I'm using an entity together with ajax. I want the full table i provice with Entity framework ina grid created with JavaScript. The table I'm currently sending has less than 140 lines. My code works if I only have 50 lines in the table a few more an I get the following error: {"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":" at System.Web.Script

Problem deserializating JSON Date in C# - adding 2 hours

痴心易碎 提交于 2019-12-06 03:31:15
问题 We are having such a nasty problem when deserializating a JSON date to a C# DateTime. The code is: JavaScriptSerializer serializer = new JavaScriptSerializer(); jsonTrechos = jsonTrechos.Replace("/Date(", "\\/Date(").Replace(")/", ")\\/"); Trecho[] model = serializer.Deserialize<Trecho[]>(jsonTrechos); The jsonTrechos is a string of json2.js's JSON.stringify(); . Problem is: the deserialization works, bur all dates of the Trechos objects are added with 2 hours. My timezone is Brazil (UTC -3)