javascriptserializer

VB.NET problem converting DataTable to JSON

只谈情不闲聊 提交于 2019-12-24 06:34:00
问题 Ok so I'm trying to use the JavaScriptSerializer to work with this code. However it crashes when it reaches the last line; Dim json As New String(sr.Serialize(dt)) I get this error message; A circular reference was detected while serializing an object of type 'System.Reflection.Module'. I would really appreciate any insights that could help solve this problem. 回答1: Circular reference means that serialising the object would result in an infinite loop. For example if you would try to serialize

JavaScriptSerializer deserialize object “collection” as property in object failing

安稳与你 提交于 2019-12-23 09:32:18
问题 I have a js object structured like: object.property1 = "some string"; object.property2 = "some string"; object.property3.property1 = "some string"; object.property3.property2 = "some string"; object.property3.property2 = "some string"; i'm using JSON.stringify(object) to pass this with ajax request. When i try to deserialize this using JavaScriptSerializer.Deserialize as a Dictionary i get the following error: No parameterless constructor defined for type of 'System.String'. This exact same

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

冷暖自知 提交于 2019-12-22 01:37:10
问题 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

JSON deserialization to inherited types

偶尔善良 提交于 2019-12-20 18:06:39
问题 I have a data table in my database where I store various settings. Since they are of any type (even complex object graphs) I decided to store their values as serialized JSON strings. Let's say that I serialized a List<ItemBase> . Serialized string looks just fine. But the problem is that list items are of various types that are inherited from ItemBase (which may as well be abstract for what I care). Question Which (de)serialization class/library should I use so my JSON strings will be

Deserializing JSON result with Json & JavaScriptSerializer

风流意气都作罢 提交于 2019-12-19 10:48:37
问题 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

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

不打扰是莪最后的温柔 提交于 2019-12-19 09:06:26
问题 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

JSON serializing an object with function parameter

拜拜、爱过 提交于 2019-12-18 15:06:03
问题 I have this C# object: var obj = new { username = "andrey", callback = "function(self) { return function() {self.doSomething()} (this) }" } I need to JSON serialize it to pass to the browser in ajax call. I use JavascriptSerializer, but it serializes to the following JSON: {"username":"andrey", "callback": "function(self) { return function() {self.doSomething()} (this) }"} but what I need is: {"username":"andrey", "callback": function(self) { return function() {self.doSomething()} (this) }}

JSON serializing an object with function parameter

怎甘沉沦 提交于 2019-12-18 15:05:34
问题 I have this C# object: var obj = new { username = "andrey", callback = "function(self) { return function() {self.doSomething()} (this) }" } I need to JSON serialize it to pass to the browser in ajax call. I use JavascriptSerializer, but it serializes to the following JSON: {"username":"andrey", "callback": "function(self) { return function() {self.doSomething()} (this) }"} but what I need is: {"username":"andrey", "callback": function(self) { return function() {self.doSomething()} (this) }}

Serializing a decimal to JSON, how to round off?

大城市里の小女人 提交于 2019-12-18 11:44:40
问题 I have a class public class Money { public string Currency { get; set; } public decimal Amount { get; set; } } and would like to serialize it to JSON. If I use the JavaScriptSerializer I get {"Currency":"USD","Amount":100.31000} Because of the API I have to conform to needs JSON amounts with maximum two decimal places, I feel it should be possible to somehow alter the way the JavaScriptSerializer serializes a decimal field, but I can't find out how. There is the SimpleTypeResolver you can

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

笑着哭i 提交于 2019-12-18 11:38:21
问题 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