Questions tagged [datacontractjsonserializer]

DataContractJsonSerializer is a .NET component that makes it possible to directly serialize .NET objects into JSON data and to deserialize such data back into instances of .NET types.

DataContractJsonSerializer is part of the Microsoft (version 3.5 onwards). It makes it possible to directly serialize .NET objects into data and to deserialize such data back into instances of .NET types.

As with (with which it shares an abstract base class XmlObjectSerializer), DataContractJsonSerializer is intended to serialize data contract types, thus appropriate data contract attributes may be applied to control the serialization of objects from and to JSON.

188 questions
2
votes
1 answer

DataContractJsonSerializer.ReadObject pass a different type of object

I have a problem, a certain http API can return two different types of JSON objects. Unfortunately I have to live with it. I have to work with it from .NET 3.5 code, and I use DataContractJsonSerializer to deserialize the responses from the service.…
Myar
  • 112
  • 10
2
votes
1 answer

Deserializing JSON, nested object properties to be in parent object. C#

I have following JSON that I'm writing object model to deserialize into: { "company_webhooks": [ { "company_webhook": { "id": 42, "url": "https://keeptruckin.com/callbacktest/842b02", "secret":…
katit
  • 17,375
  • 35
  • 128
  • 256
2
votes
1 answer

C# DataContractJsonSerializer ReadObject not throwing error if member is missing

I have a user class like public class User { public string UserName {get;set;} public string Application {get;set;} } Now, I am using it like var jsonSerializer = new DataContractJsonSerializer(typeof(User)); var objApp =…
Milind Thakkar
  • 980
  • 2
  • 13
  • 20
2
votes
2 answers

Deserializing JSON 2-dimensional array of values

I've got a 2-dimensional array of values in JSON format: [[57, 2], [57, 2], [58, 2], [55, 2], [60, 2], [54, 1], [59, 11]] Each of the pairs actually contains a pair of unrelated readings, and there is one pair for each minute. So in the first min,…
Steve Ward
  • 1,207
  • 3
  • 16
  • 42
2
votes
2 answers

Deserializing a JSON array of mixed types

I'm having trouble deserializing a JSON array of mixed types using the DataContractJsonSerializer class. I've spent a bunch of time looking for a solution to no avail, so I thought I'd go ahead and ask here. Basically, I am getting a JSON string…
Mike
  • 21
  • 1
  • 2
2
votes
1 answer

Using DataContractJsonSerializer

I am trying to host a WCF service that responds to incoming requests by providing a json output stream. I have the following type [DataContract] …
Cranialsurge
  • 6,104
  • 7
  • 40
  • 39
2
votes
2 answers

c# DataContractJsonSerializer returns null

Hello I have this code: trough HttpClient I recieve this json string: {"group":3,"data":[{"count":1,"providerName":"BetaDigital","providerNo":12},{"count":139,"providerName":"Free to air","providerNo":1}]} var serializer = new…
petrtim
  • 267
  • 1
  • 2
  • 10
2
votes
1 answer

Way to Deserialize JSON from HttpWebResponse without 3rd party frameworks

I'm trying to keep from depending on open source or third party libraries such as Json.NET to parse incoming JSON from an HttpWebResponse. Why? Because the more reliance on open source frameworks to aid in your implementations, the more your app…
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
2
votes
1 answer

DataContract Json Serializer and missing bracket in collection of items

When I de-serialize/serialize and data contract to a json format my collection of items is missing the bracket and is causing it fail when posting to web api. Here is the json in the correct format with [] brackets { "basket": { …
Etienne
  • 179
  • 3
  • 12
2
votes
2 answers

Using DataContractJsonSerializer to create a Non XML Json file

I want to use the DataContractJsonSerializer to serialize to file in JsonFormat. The problem is that the WriteObjectmethod only has 3 options XmlWriter, XmlDictionaryWriter and Stream. To get what I want I used the following code: var js = new…
Amit Raz
  • 5,370
  • 8
  • 36
  • 63
2
votes
1 answer

Serialize an object using DataContractJsonSerializer as a json array

I have a class which contains a list of items. I want to serialize an instance of this class to json using the DataContractJsonSerializer as a json array. eg. class MyClass { List _items; } class MyItem { public string Name…
rekna
  • 5,313
  • 7
  • 45
  • 54
2
votes
2 answers

Using DataContractJsonSerializer, deserialization of JSON string into C# object which has list & interface as properties

I am working on a c#.dotNet project which invokes a 3rd party REST service. Sample Class Structure : [Serializable] [DataContract(Name = "MainClass")] [KnownType(typeof(Class1))] [KnownType(typeof(Class2))] public class MainClass :…
B Bhatnagar
  • 1,706
  • 4
  • 22
  • 35
2
votes
1 answer

Is it possible to use JsonReaderWriterFactory to convert XML to JSON without using DataContractJsonSerializer?

I need a generic routine that takes any valid XML and converts it to JSON without knowing the underlying data type. I know that this is easily done with Json.Net and I also know how to do it with the DataContractJsonSerializer but our organisation…
2
votes
2 answers

How to deserialize a JSON response with list of objects with variable name starting with _ or $

How to deserialize the web response like this: [{"_exp":"2014-06-05T23:58:03.859Z","_id":"123","$val":"dabg"}, {"_exp":"2014-07-05T23:58:03.859Z","_id":"143","$val":"dabg"}] Here my specific question is that I am not able to create a response…
2
votes
1 answer

Can DataContractJsonSerializer handle cyclic references?

Are there any serialization/deserialization scenarios that DataContractSerializer can handle, while DataContractJsonSerializer can't? In particular, I am thinking of circular references: this MSDN page explains how circular references can be managed…