javascriptserializer

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

不羁岁月 提交于 2019-12-05 03:34:08
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) { var serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new MyProject

error CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web'

南楼画角 提交于 2019-12-04 22:13:43
I am trying to use JavaScriptSerializer in my application. I initially received Cannot find JavaScriptSerializer and I solved it by adding: using System.Web.Script.Serialization; But then the sub-keyword Script is underlined with a blue line: The type or namespace 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) So I added to the project a reference to: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Extensions.dll That didn't help. I am still receiving the same blue underline with same error. The

Using JavaScriptSerializer.DeserializeObject how can I get back a Dictionary that uses a case insensitive string comparer?

[亡魂溺海] 提交于 2019-12-04 19:57:36
问题 I have some JSON that I need to deserialize so I'm using JavaScriptSerializer.DeserializeObject like: var jsonObject = serializer.DeserializeObject(line) as Dictionary<string, object>; The problem is that the Dictionary that comes back has a case-sensitive key comparer, but I need case-insensitive. Is there some way to get back a Dictionary that is case-insensitive? EDIT: I'd prefer not to copy the data to a new structure, since I have a lot of data and this will be costly. 回答1: Just create a

String exceeds maxJsonLength with less than 250kb

最后都变了- 提交于 2019-12-04 12:32:51
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.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat

Web.config jsonSerialization maxJsonLength ignored

穿精又带淫゛_ 提交于 2019-12-04 07:19:46
I have an MVC3 application running under .NET 4.0 and when I use JavascriptSerializer.Deserialize I'm getting an error. Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. Reading Can I set an unlimited length for maxJsonLength in web.config I put the jsonSerialization maxJsonLength key in my web.config but it gets ignored. Though I can set the JavaScriptSerializer.MaxJsonLength property in code and it works fine. I would like to have the value in the Web.config rather than code. Here

How to parse JSON objects with numeric keys using JavaScriptSerializer

与世无争的帅哥 提交于 2019-12-04 04:53:36
问题 I have an object like below to be deserialized in C#. I am wondering how I can parse it. I tried following this example here, but am stumped on how I can get my class to recognize the key of each object (the 2 and the 3 below). The JSON string below basically represents 2 transactions. I would like to convert each transaction representation into a Transaction object and put it into an array of Transaction object. { "2": { "id": "2", "user_id": "59", "offer_id": "1234" }, "3": { "id": "3",

JavascriptSerializer serializing property twice when “new” used in subclass

天大地大妈咪最大 提交于 2019-12-02 11:09:18
问题 Trying to create a service to return an object that has many shared properties, but one property should be highly limited in some situations. This is resulting in odd and undesired behaviour, where a property name is reused in the serialized output, resulting in incorrect behaviour in the browser. Here is an example that can be pasted into LINQPad (if you add a reference to System.Web.Extensions ) to see the problem: void Main() { System.Web.Script.Serialization.JavaScriptSerializer json =

c# Deserialize JSON list of object error

不打扰是莪最后的温柔 提交于 2019-12-02 06:52:50
问题 when I deserialize to list of object it work but when I deserialize to a object with list type it errors out. Any idea how to make it work? page name: testjson.aspx using System; using System.Collections.Generic; using System.Web.Script.Serialization; namespace Web.JSON { public partial class testJson : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string json = "[{\"SequenceNumber\":1,\"FirstName\":\"FN1\",\"LastName\":\"LN1\"},{\"SequenceNumber\":2,\"FirstName\

JavascriptSerializer serializing property twice when “new” used in subclass

喜欢而已 提交于 2019-12-02 04:39:10
Trying to create a service to return an object that has many shared properties, but one property should be highly limited in some situations. This is resulting in odd and undesired behaviour, where a property name is reused in the serialized output, resulting in incorrect behaviour in the browser. Here is an example that can be pasted into LINQPad (if you add a reference to System.Web.Extensions ) to see the problem: void Main() { System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer(); json.Serialize(new Full(true)).Dump(); json

c# Deserialize JSON list of object error

倾然丶 夕夏残阳落幕 提交于 2019-12-02 04:28:25
when I deserialize to list of object it work but when I deserialize to a object with list type it errors out. Any idea how to make it work? page name: testjson.aspx using System; using System.Collections.Generic; using System.Web.Script.Serialization; namespace Web.JSON { public partial class testJson : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string json = "[{\"SequenceNumber\":1,\"FirstName\":\"FN1\",\"LastName\":\"LN1\"},{\"SequenceNumber\":2,\"FirstName\":\"FN2\",\"LastName\":\"LN2\"}]"; //This work IList<Person> persons = new JavaScriptSerializer()