json.net

null value exception thrown when deserializing null value JSON.net

Hi Friends I am trying to deserialize a hidden control field into a json object the code is as follows Dim settings As New Newtonsoft.Json.JsonSerializerSettings() settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of testContract)(txtHidden.Text, settings) But I am ...

How to serialize and unserialize to/from a C# class?

Hello, I have an object in Javascript that looks like this function MyObject(){ this.name=""; this.id=0; this..... } I then stringify an array of those objects and send it to an ASP.Net web service. At the webservice I want to unserialize the JSON string so I can deal with the data easily in C#. Then, I want to send an array of...

How can I return json from my WCF rest service (.NET 4), using Json.Net, without it being a string, wrapped in quotes?

UPDATE 10/19/2010 I know I asked this question a while ago, but the workarounds shown in these answers are hardly satisfactory, and this is still a common problem for many. WCF just isn't flexible. I started my own open source C# library for creating REST services without WCF. Check restcake.net or rest.codeplex.com for info on said l...

Upgrade of NewtonSoft JSON.NET not implicitly serialising protected members

Hi, I have just updated my version of NewtonSoft JSON.NET from version 3.0.0 to 3.5.0 and I have noticed that protected members are not implicitly serialised. I have the following class: public class SimpleFileContainer : IDto { public virtual string Name { get; protected set; } public virtual string Path { get; protected set...

How to set Json.Net as the default serializer for WCF REST service

Is it possible to override the default WCF DataContractSerializer behaviour when Serialize/DeSerialize entities and use JSON.NET instead? I have the following service contract for handling the City entity. For design reasons the City entity has IsReference=true, and therefore the default DataContractSerializer raise errors. For the "GE...

json object setting to default /null value

Hi i am using json.net for converting a json string, i am just pasting a small string here: "incentive_type":{"cost":0,"id":4} "incentive_type":{"cost":{"points":400,"denom":null,"acc":{"foil":{},"rates":{}}},"id":4} now the incentive_type i have declared as : public class incentive_type { public cost cost { get; set; } publ...

Xml to Json Conversion using Newtonsoft Json.Net: Removing @ prefix?

I am using Newtonsoft Json.Net to convert Xml to Json. Following Xml <root> <person id="1"> <name type="first">Alan</name> <url>http://www.google.com&lt;/url&gt; </person> <person id="2"> <name type="last">Louis</name> <url>http://www.yahoo.com&lt;/url&gt; </person> </root> Is converted to following Json. { "root":...

How can I best utilize Json.NET to modify parts of an existing JSON object?

Example: I have the following JSON object. {"currentVersion" : "10.0", "folders" : [], "services" : [ {"name" : "nyc", "type" : "MapServer"}, {"name" : "philly", "type" : "MapServer"} ] } I want to be able to remove one or more items from the services array based on the value of the name attribute. For instance, I w...

name-value-pair string to Json

Trying to get an object out of str1=X&str2=Y using Newtonsoft.Json Getting: "Unexpected character encountered while parsing value: s. Line 1, position 1." Am i way off expecting this to work? public class MyTest { public string str1 { get; set; } public string str2 { get; set; } } public MyTest GetJson() { data = "s...

Easiest way to parse a Javascript date in C#?

I see that JSON.NET has a DateTime converter: string javascriptJson = JsonConvert.DeserializeObject(entry, new JavaScriptDateTimeConverter()); However I don't have a JSON object, I simply have a string: /Date(1276146000000-0500)/ I could create an object, add the date, then parse it, but this seems common enough that there should b...

Serialize a .net Object directly to a NetworkStream using Json.net

Hello Is there any way to have Json.net serialize an object directly to a NetworkStream? In other words, have Json.net send the serialized result to the network as it serializes the object (in a streaming fashion). I would like to avoid having to serialize the object to memory and then send it via the NetworkStream. Any thoughts? Re...

Order of serialized fields using JSON.NET

Short and sweet: Is there a way to specify the order of fields in a serialized JSON object using JSON.NET? It would be sufficient to specify that a single field always appear first. ...

Sorting a JSON Object using Linq

I am getting a response back from a Google Search Appliance suggest service in the form of JSON in the following format string jsonString = @"{ ""query"": ""t"", ""results"": [ { ""name"": ""tom"", ""type"": ""suggest"" }, { ""name"": ""tim"", ""type"": ""suggest"" }]}"; I want to sort the results list by name alphabeticaly and change...

json asmx and that pesky d:

I have looked through lots of Posts and have not been successful in determining how to get rid of the pesky d in the response coming from my asmx web service, as in {"d":{"Response":"OK","Auth-Key":"JKPYZFZU"}}. This is being created by my class 'public Dictionary UserDevice' by returning the Dictionary object. I would be perfectly h...

How to deserialize object derived from Exception class using Json.net (C#)?

I'm trying to deserialize object derived from Exception class: [Serializable] public class Error : Exception, ISerializable { public string ErrorMessage { get; set; } public Error() { } } Error error = JsonConvert.DeserializeObject< Error >("json error obj string"); It gives me error: ISerializable type 'type'...

Error while parsing a Json object

From my jQuery file, I call a function from my controller which returns a Json object, as below: [AcceptVerbs(HttpVerbs.Get)] public ActionResult MatrixTypes() { var matrix = Enum.PricingMatrixType(); return Json(matrix); } The call is made by the following function, I'm posting only ...

Json.net / ASP.NET web service - How to return and parse dates?

After much head scratching as to why my returned Json string is breaking JSON.parse, I have realized that it is the returned dates that it doesn't like. .net property:- [JsonProperty("start")] [JsonConverter(typeof(JavaScriptDateTimeConverter))] public DateTime Start { get { return _start; } set { _start...

Json.NET and generic dictionaries

It seems impossible to (de-)serialize a generic dictionary using Json.NET out of the box. class KeyClass { public KeyClass(string p1, string p2) { prop1 = p1; prop2 = p2;} public string prop1 { get; set; } public string prop2 { get; set; } } class ValueClass { public ValueClass(string pa, string pb) { propA = pa; propB ...

How to convert c# generic list to json using json.net?

I am converting my datatable to c# generic list. DataTable dt = mydata(); List<DataRow> list = dt.AsEnumerable().ToList(); Now how can i convert this list to json using json.net? Any suggestion. Sample of json format should be like this, {"Table" : [{"userid" : "1","name" : "xavyTechnologies","designation" : "", "phone" : "9999999...

How to loop through JSON Data?

I have an ashx page that returns the following JSON data that I would like to be able to loop through and add to values to a bunch of li's in a ul. My question is how do I loop through to retrieve the values. The data that is returned from the ashx look slike this {"ImageCollection": { "Images": [ ...