Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
146 views

Using C# DataContractJsonSerializer to deserialize a string property that contains a json. Throws XmlException

I'm trying to deserialize a class that has a string property called Metadata that contains a json. I don't want to deserialize whatever is in that json, I just want to copy that text to my string ...
NKatic's user avatar
  • 17
1 vote
1 answer
64 views

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 ...
Daniel Schmid's user avatar
0 votes
0 answers
192 views

Deserialize protobuf json using DataContractSerializer

I will give a shot asking here as seemingly simple question but hard to find answer.. maybe for some people this is a common sense.. When one microservice uses Protobuf to build classes and serialize ...
swcraft's user avatar
  • 2,096
0 votes
0 answers
123 views

ExtensionDataObject - Members are private. How do I read/write?

The goal is to read/write json files that contain custom properties. The typical advice is to use the ExtensionDataObject class. However, I can't find any information online as to how I actually read/...
LeiMagnus's user avatar
  • 311
0 votes
1 answer
215 views

DataContractJsonSerializer contains invalid UFT8 bytes

When I try to deserialize a JSON file with a 'Ñ' I get the exception: 'Exception has been thrown by the target of an invocation. ---> System.Xml.XmlException: '� 1' contains invalid UTF8 bytes. ---&...
Daniel's user avatar
  • 1
0 votes
0 answers
137 views

DataContractJsonSerializer with NetworkStream

i want to use the DataContractJsonSerializer class in combination with the TcpClient to receive and send JSON serialized objects. I am able to send JSON serialized objects but the receiving part does ...
user3452883's user avatar
2 votes
3 answers
303 views

How to pass none english letters to Json

I'm working on a Xamarin Forms app for Android & iOS I'm trying to figure out how to pass none english letters to Json file. My language is Swedish and whenever I use characters like (Å, Ä, Ö) the ...
Jaser's user avatar
  • 265
-3 votes
1 answer
313 views

In C#, how to parse json which has a string containing a comma [closed]

I am using the DataContractJsonSerializer in C# and I am trying to deserialize the below Json array, how ever it is failing because the "PlaceName" string value contains a comma. Error ...
davey1971's user avatar
0 votes
0 answers
50 views

Setting an additional caller-defined context for DataContractJsonSerializer

For BinaryFormatter I can set an additional caller-defined context, which will be passed as parameter to the method called after deserialization, e.g. decorated with [OnDeserialized] attribute. ...
Rekshino's user avatar
  • 7,247
0 votes
0 answers
152 views

Does IExtensibleDataObject work with EmitDefaultValue option and DataContractJsonSerializer?

I want to design an API that accept some generic contract and also can store additional values that extends generic schema. It looks like IExtensibleDataObject machinery was built for similar task and ...
Nikita Sivukhin's user avatar
0 votes
0 answers
262 views

Parse JSON string to dynamic object without creating class using System.Runtime.Serialization.Json

The JSON string that I want to parse is the response from the API and the response may not have fixed properties. So cannot create a class with properties to parse the JSON string. I tried to parse ...
Vaibhav Ghorpade's user avatar
0 votes
0 answers
88 views

How does DataContractJsonSerializer.ReadObject(XmlReader, Boolean) read json from an XmlReader?

I'm looking at the ms documentation for DataContractJsonSerializer which lists an overload for ReadObject: ReadObject(XmlReader, Boolean) The documentation states: Reads an XML document mapped from ...
Jeremy's user avatar
  • 46k
0 votes
1 answer
325 views

System.Text.Json.Deserialize an array into C# class

First off, I am working with the Google recaptcha RESTful service trying to get the JSON object into a class. With WSDL's, Visual Studio will generate all this code for you so that it is easy to work ...
Sam Carleton's user avatar
  • 1,401
0 votes
0 answers
323 views

C# DataContract force PascalCase output

The DataContract likes to accept the input properties in PascalCase (as the property names are in PascalCase as well in C#) unless I manually set the property name to camelCase (using JsonProperty). ...
Arvind Sasikumar's user avatar
0 votes
1 answer
991 views

Getting InvalidDataContractException while serializing with DataContractJsonSerializer

I have the following Json stored as Dynamics Environment Variable: { "LogLevel": 3, "ServiceEndpointId": "11111111-2222-3333-4444-555555555555", "ServiceEndpointType&...
Paul Richardson's user avatar
1 vote
1 answer
384 views

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: &...
Attila Lazúr's user avatar
0 votes
1 answer
196 views

VB.NET DataContractJsonSerializer Nested Object Formatting

I have a problem with the outcome of a serialization. The class i serialize looks like this: <Runtime.Serialization.DataContract()> Public Class ResponseJSON <Runtime....
Tom Siegel's user avatar
1 vote
1 answer
3k views

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 ...
Nick Tucker's user avatar
2 votes
1 answer
1k views

How to serialize JSON string containing date and time property using DataContractJsonSerializer?

we are trying to serialize a JSON object [as a string] into a custom class. While we rather not use any third-party packages such as Newtonsoft.Json or Json.NET, we tried to utilize ...
Mahyar Mottaghi Zadeh's user avatar
1 vote
1 answer
338 views

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": "...
Jhon Hernández's user avatar
1 vote
0 answers
149 views

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 ...
Noa's user avatar
  • 11
1 vote
0 answers
465 views

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 ...
Nicke Manarin's user avatar
1 vote
2 answers
741 views

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 ':...
Rakesh Kumar's user avatar
1 vote
1 answer
134 views

JSON nested array. C# DataContractJsonSerializer returns null

I get this JSON: {"lastUpdateId":836890951,"bids":[["0.02106900","0.56000000"],["0.02106800","1.38000000"],["0.02106600","3.63600000"],["0.02106500","34.28000000"],["0.02106100","41.49400000"...
Роман's user avatar
1 vote
1 answer
255 views

WCF REST service dictionary serialization

I'm having trouble with serializing dictionary in my WCF service. [DataContract] public class UserInfo { [DataMember] public Guid ID { get; set; } [DataMember] ...
zhuber's user avatar
  • 5,494
1 vote
0 answers
446 views

Serialize parameters for remote procedure call

I want to design a RPC scenario. The client call is serialized using DataContractJsonSerializer. The serialized request is passed to service. Service deserializes the request and use it to invoke the ...
konjac's user avatar
  • 787
-2 votes
1 answer
108 views

Retrieving json Data C# [closed]

Not able to retrieve json data below is the json data please suggest me. { "creator_email": "[email protected]", "vcard_info": "BEGIN:VCARD\r\nVERSION:2.1\r\nFN;CHARSET=utf-8:Hyder Hafir\r\...
Amrutha's user avatar
0 votes
0 answers
2k views

Encountered unexpected character ‘<’” error serializing in DataContractJsonSerializer.ReadObject(stream)

we're sending HTTP request to Bing maps with address details to get back the address map point. The response of the HTTP request is read as stream async, this stream is then deserialized to Bing ...
Marwan's user avatar
  • 57
0 votes
2 answers
2k views

XmlException: Encountered an unexpected character '

Hello everyone I switched to Json serialization, serialization work perfectly this time the problem come from deserialization I have a exception ... the error: XmlException: Encountered an ...
NEOX's user avatar
  • 1
0 votes
1 answer
91 views

Can I map a JSON element "@somename"? [duplicate]

I’m targeting .net framework 4.7 with a winforms application. I started by following this article https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/console-webapiclient so I am using ...
AlecJames's user avatar
0 votes
0 answers
195 views

C# save to json file using DataContractJsonSerializer

I want to save the data to the JSON file. Using many examples on the internet, I tried to do it, but it still does not work. [DataContract] [KnownType(typeof(PressureSensor))] [KnownType(typeof(...
Adrianna Tyszkiewicz's user avatar
2 votes
1 answer
2k views

Why cant I serialize a property that has a private setter (C#, json)

I'm using dotnet core 2.1 and made a helper to serialize from and to JSON. It's built on System.Runtime.Serialization.Json that ships with dotnet core. I don't want to use JSON.NET lib for some ...
kipy's user avatar
  • 592
0 votes
0 answers
258 views

DataContractJsonSerializer stringifies DateTime values inside dictionaries during deserialization

I need a JSON serializer/deserializer that comes with .NET. I cannot use Newtonsoft Json.NET. As far as I know, that leaves me with JavaScriptSerializer and DataContractJsonSerializer. ...
Bartosz's user avatar
  • 4,716
1 vote
0 answers
796 views

Deserializing Part Of A JSON To Dictionary using C# DataContract [duplicate]

I'm parsing some JSON which looks like this using DataContract. The issue that i have is parsing "ThresholdRules" as dynamic as possible. Keep in mind the objects inside "ThresholdRules" go up to 99 ...
Chejua's user avatar
  • 55
2 votes
1 answer
298 views

Deserialization from JSON into List of Objects

I am attempting to deserialize a json file into a List of Objects. The JSON file requires that I use UTF8. I am attempting to do it this way below. FileStream reader1 = new FileStream(fileName, ...
visuslov's user avatar
1 vote
1 answer
837 views

Problem when serializing objects with strings that contain "/"

I am using DataContractJsonSerializer to serialize an object, and to do this I am using the following function: public static string Serialize<T>(T obj) { string returnVal = ""; try ...
KansaiRobot's user avatar
  • 9,383
0 votes
0 answers
59 views

ObjectToJson thorwn System.OutOfMemoryException

I use this construction. public static string ObjectToJson<TObject>(TObject obj) { try { using (MemoryStream memoryStream = new MemoryStream()) { ...
DimaS's user avatar
  • 38
0 votes
1 answer
1k views

Optional fields with DataContractJsonSerializer (how to change the default)

I have been using DataContractJsonSerializer succesfully to serialize an object into json. The great thing about this is that I can work with optional fields (that may or maynot be serialized). For ...
KansaiRobot's user avatar
  • 9,383
0 votes
2 answers
454 views

DataContractJsonSerializer Deserialization problem

I need to De-serialize Json array which is given bellow .... [ { "GeoType": 1, "ID": "2650f7d2-7a5e-4b63-856c-07600fa2a854", "Name": "Afghanistan", "CapitalCity": ...
Saday Sarkar's user avatar
0 votes
0 answers
243 views

Keep JSON Object as String while Serializing with DataContractJsonSerializer

Currently, I am receiving a dynamic JSON response from an API which I am trying to parse. An example of the JSON that is received looks as follows: { "data": [ { "Id": "...
Riaru Neimu's user avatar
0 votes
1 answer
275 views

Controlling object creation when deserializing using DataContractJsonSerializer

I am using DataContractJsonSerializer to serialize/deserialize my object to/from JSON string. My object contains a Dictionary<string, string> data member, and I want to make this dictionary ...
codewarrior's user avatar
0 votes
1 answer
434 views

how to serialize and deserialize a tuple

How to serialize a JSON to tuple within F# (and vice versa)? JSON Schema { "name": "test", "type": "document", "id": "e3c7373c-f4bc-4ffa-9a01-7c7d9f83e4cf" } Tuple let document = ("test", "...
App2015's user avatar
  • 983
1 vote
1 answer
636 views

JSON parsing collection of records

I've been struggling with this for long, I believe there's something wrong with my record design. MY json looks like below. I posted this earlier as a part of another question but didn't get full ...
App2015's user avatar
  • 983
1 vote
1 answer
487 views

JSON serialization for option types

I'm running across an issue when I define a field of option type while serializing for JSON. Before works (without option) [<DataContract>] type Article = { [<field: DataMemberAttribute(...
App2015's user avatar
  • 983
3 votes
1 answer
4k views

EnumMemberAttribute Value is ignored by DataContractJsonSerializer

This is my code: [DataContract] // (Name = "Type")] public enum Purpose { [EnumMember(Value = "definitionTarget")] DefinitionTarget = 0, [EnumMember(Value = "definitionSource")] ...
Vadim Berman's user avatar
  • 2,003
1 vote
1 answer
3k views

DataContractJsonSerializer with object type member

I have the following serialization method: private string Serialize(Message message) { byte[] json; using (var ms = new MemoryStream()) { var ser = new ...
Xavier W.'s user avatar
  • 1,360
0 votes
0 answers
126 views

Serializing JSON with DataContractJsonSerializer in C# gives trailing null characters (\0) [duplicate]

When serializing a JSON I get trailing null characters which makes my unit test fail. The serializer looks like this: public static string SerializeJSON<T>(T ObjectToSerialize) { ...
Erik's user avatar
  • 21
2 votes
1 answer
2k views

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 ...
Myar's user avatar
  • 112
9 votes
1 answer
18k views

Deserialize json with C# .NET Core

Im trying to deserialize data that Ive got over POST in JSON format but having some problem. The error message is: SerializationException: Expecting state 'Element'.. Encountered 'Text' with name '...
Michal Takáč's user avatar
1 vote
1 answer
1k views

Json Deserializing not populating properties

I'm deserializing a third party string like this: {"status":4,"errors":[{"Duplicate Application":"Duplicate Application"}]} I use my standard extension method: public static T DeserializeJson<T&...
John Ohara's user avatar
  • 2,901