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

Serialize complex dictionary with DataContractJsonSerializer

With .NET 4.5 version of DataContractJsonSerializer and with help of DataContractJsonSerializerSettings.UseSimpleDictionaryFormat I can serialize dictionaries. So for example this dictionary: var dic = new Dictionary { { "Level",…
Aleksandr Ivanov
  • 2,778
  • 5
  • 27
  • 35
2
votes
4 answers

Deserialization of JSON object by using DataContractJsonSerializer in C#

I'm sure this question has been asked over and over again, but for some reason, I still can't manage to get this to work. I want to deserialize a JSON object that contains a single member; a string array: [{"idTercero":"cod_Tercero"}] This is the…
stvn03
  • 43
  • 2
  • 2
  • 5
2
votes
1 answer

How do I efficiently deserialize a JSON object with nested objects using a stream reader in C#?

I would like to efficiently deserialize JSON object which contains a nested array of JSON objects. For example, a JSON directory listing could contain a root JSON file system object with a recursive array of file system objects. { "bytes": 0, …
Keith Morgan
  • 721
  • 7
  • 17
2
votes
1 answer

Deserializing JSON using System.Runtime.Serialization.Json

I'm having issues with deserializing some json with C#. Suppose this is a snippet of the json I'm being sent (repeated many times, but nothing else other than id/name): [ { "id":0, "name":"N/A" }, { "id":1, …
Craton
  • 23
  • 1
  • 3
1
vote
2 answers

Windows Phone, How to deserialize json which has nested Array

I am now doing a windows phone project, and need to request to a web service for some json data. if the json structure is like [Dictionary1, Dictionary2, Dictionary3 ] then, DataContractJsonSerializer works fine. but the next…
1
vote
1 answer

Silverlight 4 DataContractJsonSerializer, private fields of a derived class

I use DataContractJsonSerializer to deserialize json data in Silverlight 4. Json data key names do not match my class property names; so I guess I have to use DataMemberAttribute. So I did the following: [DataContract] public class Person :…
1
vote
1 answer

Deserializing JSON object with unknown fields

The question is similar to Deserializing JSON with unknown fields but I would like to use the built in DataContractJsonSerializer instead. So I have JSON data like that: { "known1": "foo", "known2": "bar", "more":{ "unknown12345": { "text": "foo",…
Marco
  • 2,190
  • 15
  • 22
1
vote
1 answer

JSON DataContract dual types for string and string array

I'm consuming a REST API from an adventurous team. They're providing two endpoints where both return a similiar but not equal response. I'm deserializing the responses using the DataContractJsonSerializer. Endpoint A response: { "message": "Hello…
1
vote
1 answer

JSON to c# class serialization returns null

I have a webservice, which I want to POST JSON data. I want to serialize the submitted data into a class and some of the serialized data always returns null. Here is the problematic part of the json: "contacts": { ..."1": { …
1
vote
1 answer

Why do DataContractJsonSerializer and Json.NET serialization of DateTimeOffset produce different json?

I have an issue that I am trying to understand regarding the way that DateTimeOffset values are serialized and deserialized using DataContractJsonSerializer and Json.NET's JsonConvert. I have the following class [DataContract] public class…
1
vote
1 answer

C# how can I get a count of Json with several levels

I have a json like this one that comes from an api. I´m using oauth2 so i got the token, then I request the data. I want to count the name inside resources, to know how many are. { "startDate": "2019-06-23T16:07:21.205Z", "endDate":…
1
vote
0 answers

Serialization & backward compatibility (DataContractJsonSerializer)

I am using DataContractJsonSerializer. Currently, my serialized object contained a member of class "Settings" Now, I would like to extend my support and serialize any class that implements ISettings interface. [DataContract(Namespace =…
1
vote
0 answers

How to control the serialization of some types with DataContractJsonSerializer

I'm trying to serialize and save as JSON the settings of my app and I'm having some issues with the serialization of some types. The settings are loaded when the app starts into a ResourceDictionary which gets added into the…
Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79
1
vote
2 answers

Unable to deserialize polymorphic dictionary json due to KnownType "__type" issue

I have created a dictionary with polymorphic values in which I have saved a class object. I have successfully serialized the JSON. But I am unable to deserialize it. It gives below error: Element ':Value' contains data of the ':Sale' data contract.…
1
vote
1 answer

DataContractJsonSerializer and maxItemsInObjectGraph

How can I set the maxItemsInObjectGraph for the DataContractJsonSerializer? I get an error saying "Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the…
adrianm
  • 14,468
  • 5
  • 55
  • 102