javascriptserializer

Deserializing JSON result with Json & JavaScriptSerializer

一个人想着一个人 提交于 2019-12-01 13:36:27
here's my problem: I'm trying to deserialize json that hasn't been done by me. The format of the json is as follows: {"responseId":1200, "availableHotels":[ {"processId":"HA-84665605","hotelCode":"UKKTLT","availabilityStatus":"InstantConfirmation",...}, {"processId":"HA-28600965","hotelCode":"UKKTLT","availabilityStatus":"InstantConfirmation",...}, {"processId":"HI-63991185","hotelCode":"UKJOVF","availabilityStatus":"InstantConfirmation",...} ], "totalFound":9, "searchId":"TP-84026455"} And the following classes: getAvailableHotelResponse w/properties: hotelObj availableHotels int totalFound

In C# how can I deserialize this json when one field might be a string or an array of strings?

纵然是瞬间 提交于 2019-12-01 06:15:50
I have an asp.net-mvc website and i am reading in Json string from a Database. Here is the following json in a DB. It could look like this: {"description": "Test", "contacts": ["joe@gmail.com", "bill@yahoo.com"], "enabled": true} or this: {"description": "Test", "contacts": "joe@gmail.com, bill@yahoo.com", "enabled": true} so as you can see, the contacts field is either: a string (with items separated by commas) an array of strings. I want to convert to this class: public class MyJob { public string description; public string[] contacts; public string enabled; } when i try to assign just to a

Why does web service return data as msg.d

天涯浪子 提交于 2019-11-30 20:24:24
I found that my webmethod is returning data as { "d": [ {"id":"1","itemtxt":"Masters"}, {"id":"2","itemtxt":"Transactions"}, {"id":"3","itemtxt":"Misch. Reports"} ] } If you notice, the array is named as " d ". Why is that ? is there any rule for it? For your information I am returning a list of objects ( List<webitem> ) public class webitem { public webitem(string kid, string kval) { this.id = kid; this.itemtxt = kval; } public string id { get; set; } public string itemtxt { get; set; } } What does this " d " mean ? will it allways be same for whatever data i send from my webmethod? or it is

JavaScriptSerializer [ScriptIgnore] not effective on virtual properties?

怎甘沉沦 提交于 2019-11-30 16:14:26
问题 I have returning a Json(myObj) action result. The myObj is of type Badge The only two objects that Badge has that could cause a loop from a serializer, are: public class Badge { public Badge() { } public Badge(String Name, String Description) { this.Name = Name; this.Description = Description; } [ScriptIgnore] public virtual BadgeType BadgeType { get; set; } [ScriptIgnore] public virtual ICollection<User> Users { get; set; } public int ID { get; set; } public string Name { get; set; } public

serializing data using json.net size limit?

。_饼干妹妹 提交于 2019-11-30 07:27:24
问题 I have developed an asp.net web application and initially serialized some data to a json string using the built in javascript serializer. This became problematic as I discovered later on that there was an issue about the amount of data I was able to serialize. I kept getting ""Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property". This was quickly fixed by using json.net to serialize

Why does web service return data as msg.d

旧街凉风 提交于 2019-11-30 05:22:45
问题 I found that my webmethod is returning data as { "d": [ {"id":"1","itemtxt":"Masters"}, {"id":"2","itemtxt":"Transactions"}, {"id":"3","itemtxt":"Misch. Reports"} ] } If you notice, the array is named as " d ". Why is that ? is there any rule for it? For your information I am returning a list of objects ( List<webitem> ) public class webitem { public webitem(string kid, string kval) { this.id = kid; this.itemtxt = kval; } public string id { get; set; } public string itemtxt { get; set; } }

Using System.Web.Script.Serialization.JavascriptSerializer to deserialize JSON - how to?

隐身守侯 提交于 2019-11-30 04:04:47
Note: I posted a similar question , which was the ancestor of this question, as I was originally thinking of using JSON.NET to parse the JSON, but I'm using the built-in deserializer, so it's a different question. This is what I'm trying to do: I have a class called Item, for example. The json has many "elements" (if that's what they are called - they mimic the Item class), and each contains 3 fields: an integer named id, a string named name, and a datetime named creationTime. I would like to parse all of these Item "elements" from the json into a list of Item objects. I have created 3 fields

How to serialize a raw json field?

好久不见. 提交于 2019-11-29 13:39:15
I have a field in the db that store a json string and I want that when I return it in a json result that will be returned as json raw data and not warped with quotes as string. UPDATE 1(More Info): if you looking at the images field it contain a raw json string value but after serialize it with the JsonResult it get warped with quotes that it ok because is a type of String, how can i tell the serializer to treat the images field as a raw json data? var db = new ModelsContainer(); var res = db.Images.OrderByDescending(i=>i.DateCreated).Skip(skip).Take(take).Select( i => new { id = i.Id,

JSON Maximum length problem with ASP.NET

随声附和 提交于 2019-11-29 03:57:10
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? 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. It should be the first element under the root when you paste it in. <configSections> <sectionGroup name=

serializing data using json.net size limit?

人盡茶涼 提交于 2019-11-29 03:54:20
I have developed an asp.net web application and initially serialized some data to a json string using the built in javascript serializer. This became problematic as I discovered later on that there was an issue about the amount of data I was able to serialize. I kept getting ""Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property". This was quickly fixed by using json.net to serialize /deserialize my data. This implied that either there is no preset maximum size when using json.net to