json.net

Using Json.NET converters to deserialize properties

I have a class definition that contains a property that returns an interface. public class Foo { public int Number { get; set; } public ISomething { get; set; } } Attempting to serialize the Foo class using Json.NET gives me an error message like, "Could not create an instance of type 'ISomething'. ISomething may be an inter...

JSON.NET to C# objects

Im trying to use JSON.NET framework in a windows Form to read some information from a JSON string. But im struggling to get the Dictionaries from the 'taxonomies->topics' array and the 'clusters' { "keywords": { "anyString": [ ], "allString": { "a5349f533e3aa3ccbc27de2638da38d6": "olympics" ...

Json.NET - How to serialize a class using custom resolver

I want to serialize this class: public class CarDisplay { public string Name { get; set; } public string Brand { get; set; } public string Year { get; set; } public PictureDisplay[] Pictures { get; set; } } public class PictureDisplay { public int Id { get; set; } public string SecretKey { get; set; } publ...

Parsing JSON with JSON.NET

I have a JSON string: {"responseData": {"results": [ {"GsearchResultClass": "GblogSearch", "title":"\u003cb\u003eParis Hilton\u003c/b\u003e shops at Sydney Michelle boutique in the Beverly Glen \u003cb\u003e...\u003c/b\u003e", "titleNoFormatting":"Paris Hilton shops at Sydney Mi...

Can Json.NET deserialize a flattened JSON string with dot notation?

I have a flattened JSON: { "CaseName" : "John Doe v. State", "CaseDate" : "<some date>", "Client.FirstName" : "John", "Client.LastName" : "Doe", "Client.Email" : "[email protected]" etc... } I want to deserialize it back to this entity: public class Case() { public string CaseName { get; set; } public ...

Newtonsoft, Json.Net --> deserializing $ref and $id

Hi! So I'm trying to deserialize an object that has properties: $ref and $id. I have tried going between Dictionary as well as an object where I have specified namingconventions via JsonPropertyAttribute. Serialization works, but deserialization doesn't. The error I keep getting is: Additional text found in JSON string after fini...

Deserializing JSON data to C# using JSON.NET

I'm relatively new to working with C# and JSON data and am seeking guidance. I'm using C# 3.0, with .NET3.5SP1, and JSON.NET 3.5r6. I have a defined C# class that I need to populate from a JSON structure. However, not every JSON structure for an entry that is retrieved from the web service contains all possible attributes that are def...

Deserializing JSON into an object with Json.NET

Hello. I'm playing a little bit with the new StackOverflow API. Unfortunately, my JSON is a bit weak, so I need some help. I'm trying to deserialize this JSON of a User: {"user":{ "user_id": 1, "user_type": "moderator", "creation_date": 1217514151, "display_name": "Jeff Atwood", ... "accept_rate": 100 }} ...

Control JSON Serialization format of a custom type in .NET

I have a PhoneNumber class that stores a normalized string, and I've defined implicit operators for string <-> Phone to simplify treatment of the PhoneNumber as a string. I've also overridden the ToString() method to always return the cleaned version of the number (no hyphens or parentheses or spaces). In any views where I display the nu...

Byte array serialization in JSON.NET

Given this simple class: class HasBytes { public byte[] Bytes { get; set; } } I can put it through JSON.NET such that the byte array is base-64 encoded: var bytes = new HasBytes { Bytes = new byte[] { 1, 2, 3, 4 } }; var json = JsonConvert.SerializeObject(bytes); Then I can read it back again in this slightly over-complicated w...

JSOn.Net library JsonConvert

I'm using http://json.codeplex.com library.Im trying to convert XML to JSON and vice-versa. However they have an example,using "JsonConvert" class XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); string jsonText = JsonConvert.SerializeXmlNode(doc); I cant find "JsonConvert" in namespace "Newtonsoft.Json".Only class i've fou...

Newtonsoft.json throwing error: Array was not a one-dimensional array.

Hi everybody, I am getting an error when trying to serialize an object products. Product product = new Product(); product.Name = "Apple"; product.Expiry = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[3,2] { {"Small","40"}, {"Medium","44"}, {"Large","50"} }; string json = JsonConvert.SerializeObje...

Validating result of JsonConvert.DeserializeObject (think "try parse") using JSON.Net

I have incoming messages that I need to try and parse in my own objects structure. SOme of these are well formed JSON obejcts and some are just nonsense. I use JsonConvert.DeserializeObject<MyObject>(incmoingString); to do this. This however sometimes gives me a exception when the incoming is total garbage. Other times I get a non-comp...

Subsonic 3 : get only certain columns

Hello, I use : Subsonic 3, SQL Server 2008, Json.Net Here is my problem : I have a house table with id,lot number, address, location, ownerid and an owner table with id,name, description. I'd like to get only the owner name and address of house where location is "San Francisco". How can I do this with Subsonic? My problem is I can ...

JSon.NET DeserializeObject<List<T>> not returning list nor giving error

Hi there, I got stuck with Json.NET library and its DeserializeObject method. The Documentation is not quite clear with what could be happening here, so I would appreciate if somebody could explain how to acheive to deserialize JSON into list of User objects. I'm trying to deserialize this JSON [ {"userid":"0", "listid":1, ...

How can I get Json.net to deserialise based on a tag within the json ?

Hello, I know about the $Type but is there anyway to be less specific will this ? i.e. with the following json, {"Type":"register","Data":{"FirstName":"Mrt","Address":{"Country":"Australia"}}} or {"$Type":"Register","FirstName":"Mrt","Address":{"Country":"Australia"}} NOTE: the type doesn't have assembly or namespace, it's really...

JsonIgnore attributes not working in ASP.NET?

I've got an object in my project with circular references. I've put [JsonIgnore] above the field like so: [JsonIgnore] public virtual Foobar ChildObject { get; set; } I'm still getting circular reference errors when I serialize the object. The only fields that do not have JsonIgnore are string fields and should not cause this....

JSON.NET Deserialization in C# results in empty object

I am trying to populate a C# object (ImportedProductCodesContainer) with data using JSON.NET deserialization. ImportedProductCodesContainer.cs: using Newtonsoft.Json; [JsonObject(MemberSerialization.OptOut)] public class ImportedProductCodesContainer { public ImportedProductCodesContainer() { } [JsonProperty] pu...

How to convert datatable to json string using json.net?

How to convert datatable to json using json.net? Any suggestion... I ve downloaded the necessary binaries... Which class should i use to get the conversion of my datatable to json? Thus far used this method to get json string by passing my datatable... public string GetJSONString(DataTable table) { StringBuilder headStrBuild...

How to convert an HTML table to JSON and use the JSON with JSON.NET?

I'm asking this question because I think it's one that we run into from time to time. I needed to take an HTML table that had been manipulated client side and send the resulting table data to the server for processing. Additionally, I wanted to map this using JSON.NET directly to my business object(s). ...