Questions tagged [json.net]

Json.NET (also known as Newtonsoft.Json) is a popular high-performance JSON framework for .NET.

0
votes
1answer
27 views

Specify object location in a JSON object graph to JsonConvert

In a JSON received like so: { name { first_name: 'Foo', last_name: 'Bar' }, emails: [ {value: 'foo@bar.com' } ] Is there a way to tell JsonConvert to, for example: Fetch the value property of the ...
1
vote
2answers
46 views

Converting JSON to an object based off of another property

I am writing some models and assigning them JsonProperty attributes so I can parse them using Newtonsoft.Json. My problem is that my Laravel backend is returning a polymorphic relationship so it means ...
-1
votes
1answer
48 views

How can I deserialize a JSON string which has objects from different classes?

I would like to deserialize a JSON string which contains multiple object types. So for instance here are my two POCO classes: public class Car { [Key] public int Id { get; set; } public ...
1
vote
5answers
47 views

How to persist an object-model to JSON and serialize a dictionary as its array of values?

public class Portfolio { public string Name {get; set;} public Dictionary<string,Position> Positions {get; set;} } public class Position { public string Ticker {get; set;} ...
0
votes
2answers
35 views

Naming an Object with variable content to serialize in json file

I'm trying to serialize an object to a JSON file, but the problem is that I want to give the JSON object a variable content name. I thought I could do something like this : string codfis ="Example1"...
0
votes
0answers
39 views

Newtonsoft.Json version 12.0.0.0 throwing an exception for Hashtable serialization

When i execute my application it throws an error from Newtonsoft.Json 12.0.0.0 dll below error: Http Error 500 : { "Message":"An error has occurred.", "ExceptionMessage":"Type System.Collections....
-1
votes
1answer
28 views

Windows monitoring service write json file as output [on hold]

I am running a windows service written in VS 2017 which writes into logfile, but I want the output to be in a specific json format. I would like to ask, if there is a tool to use to write into a ...
1
vote
1answer
47 views

Json serializer returns empty string

I have a class as below code. and I tried to convert it to XML and JSON but both of them returns empty value : {} Public Class PivotSet Public Shared Property selectedlines As Boolean() ...
1
vote
3answers
61 views

Using Json.NET to convert a JObject to Dictionary<string, string> [duplicate]

Test with JSON like this: {\"key1\":\"value1\",\"key2\":\"value3\",\"key3\":[\"value4\"],\"key5\":\"value5\"}\n; invalid arguments exception: 'Newtonsoft.Json.JsonConvert.DeserializeObject>(...
-2
votes
1answer
55 views

Newtonsoft Json array deserialize or is this just a list

On https://status.cloud.google.com/incidents.json Google is using a Json Array if I'm not mistaken. I am using Newtonsoft.Json and have deserialize the json using the code below. Am I using the right ...
-1
votes
2answers
49 views

How to deserialize object to different types that depend on field's value of the context?

I don't have power to impact the incoming JSON schema so i need find solution. Say i have some simple DTO classes: public class ClassA { prop1, prop2, ... } public class ClassB { prop3, prop4, ... } ...
4
votes
1answer
44 views

Cannot apply attribute class 'JsonConverter' because it is abstract

I'm using Newtonsoft JSON library and I'm trying to deserialize a JSON. The problem is that when I use [JsonConverter(typeof(StringEnumConverter))] I get this error: Cannot apply attribute class '...
-1
votes
0answers
51 views

Visual Studio does not find Newtonsoft.json dll

I have a Visual Studio Solution in which I have several Projets. One of the projects use NewtonSoft.Json nuget, and it was once probably at 6.0.6 version, till I updated the Nugets to the latest, 12....
-1
votes
1answer
37 views

Not able to deserialise JSON file

I have one json file that I want to de serialise with newtonsoft json library. Please help. Json file [{ "2406_1": [{ "GSTIN_Status": "Active", "GSTIN": "...
0
votes
0answers
48 views

Invalid cast from 'System.DateTime' to 'System.DateTimeOffset'

I have done a lot of searching but not come up with anything which can explain my problem, which I have no doubt is trivial. I've imported Json.NET 12.0.1 into my project from NuGet. In the code ...
1
vote
1answer
63 views

Concat string inside an object?

I was wondering what is the clean way to concat a string inside an object? public class Example { public string name { get; set; } } public void BuildExample() { Example x = new Example(); ...
0
votes
1answer
40 views

Why Controller.Json and Newtonsoft Json return different results?

I have an anonymouse object which contains a collection of anonymouse objects, but changing it into json differs between controller's Json and Newtonsoft Json - how can I remove those additional ...
-1
votes
1answer
32 views

Deserializing a string into a struct with 2 uint fields

I have a JSON document containing data about all American presidents. Here is an example: { "id": 1, "name": "George Washington", "years": "1789-1797" } I have defined a class President ...
1
vote
3answers
55 views

JSON Deserializing modified class. Custom JSON Deserialize method

I had a class that I was regularly serializing and deserializing. One of its fields used to be a string to represent a road, but has since been changed to its own class. class Foo { public string ...
1
vote
2answers
42 views

Json.NET : Detect an absence of a property on Json which appears to be a member of my object

I'm trying to deserialize some Json objects using Json.NET. I'd like to be able to detect if I have a member in my class missing from the Json properties for that object. For instance, I have a class ...
-2
votes
0answers
37 views

Json Deserialiser [closed]

I am trying to deserialize a list of Objects using JsonConver.Deserialize<>(), it is deserializing but taking a lot of time when there are huge number of records. I tried various techniques like ...
0
votes
1answer
32 views

Serializing JSON Object to be passed onto String Content not working, But String Literal works when sending POST Request(Error 400)

I am trying to send a POST request to a web service. I am able to successfully do this in a console application, with a dummy request string literal. However, when I try to serialize my object using ...
0
votes
1answer
17 views

How to setup Json.NET's Converters depending on custom request's header

I need to use different Json.NET's JSON Converters depends on header. Some think like this: services .AddMvcCore() .AddJsonOptions(options => { // If(...
-2
votes
1answer
26 views

Getting error “CS1579: foreach statement cannot operate on variables of type 'ReadJson'” when using foreach loop to read and display JSON file

Trying to iterate over JSON file using foreach loop statement but seem to be getting the below error CS1579 foreach statement cannot operate on variables of type 'ReadJson' because 'ReadJson' does ...
1
vote
1answer
29 views

How to ignore underscore when deserializing [duplicate]

do we have something like what Golang has the json annotation? type FieldType struct { TypeName string `json:"typeName"` CodeType string `json:"codeType"` ...
-1
votes
0answers
38 views

How can the below code for JSON file parsing be edited to as to be more efficient if at all there is a more efficient/shorter way?

Tried parsing JSON data using https://app.quicktype.io/#l=cs but I am looking for an efficient/shorter way to be able to parse my JSON file than the below code using C# and would appreciate some help. ...
0
votes
2answers
54 views

How To concatenate json values?

i have a json with some string data. json parsing and getting values are working fine but what i want to do is to concatenate between json values like below is my json data { "Addition": { "Easy":...
0
votes
0answers
36 views

How dynamically deserialize child class? [duplicate]

How do I properly deserialize child classes? public class FilterExpression : BaseExpression { public string Selector { get; set; } public FilterOperation Operation { ...
0
votes
0answers
31 views

In consuming Api in asp net mvc and then Json Result is not display in proper format [closed]

public JsonResult Dataconsume() { polygon polys = new polygon() { UserID ="0B74E43E2F639B79A8E4BDD2D4144381", Y1 ="5089AC264CB6969DB8E1CE298FCB74DDE2B46BDEBE4829F701F0095478926B34", X2 ="...
-1
votes
1answer
60 views

JsonReaderException during deserialization of a collection with nested list

I am using Json.NET to deserialize a list that contains a list my class is as follows. However, I am getting an exception saying Illegal character now I presume it will be because I need data around ...
0
votes
0answers
38 views

JSON.NET JProperty path inconsistency

I am trying to serialize a dictionary and to use JProperty Path property for each element. To simplify the case, my dictionary has 2 elements the key of the first one is "key1" and the key of the ...
0
votes
0answers
80 views

Is NewtonSoft not supported for UWP 10.1?

We have an Xamarin project that shares code with android and ios projects. We plan To extend this sharing by creating and targeting an UWP project. So to test portability of my project to UWP i used ...
2
votes
1answer
68 views

Where did IMvcBuilder AddJsonOptions go in .Net Core 3.0?

I've just upgrade my ASP web API project from .Net core 2.0 to 3.0. I was using services.AddMvc() .AddJsonOptions(options =>options.SerializerSettings.ContractResolver ...
0
votes
1answer
57 views

Custom sorting Dictionary<string, JToken> traverse down using LINQ

I currently have Dictionary<string, JToken> item defined as an object class. This is not the root object but is the 2nd level. public class Root { public string name { get; set; } ...
0
votes
0answers
19 views

Double Precision json.net [duplicate]

In json.net under MathUtils.ApproxEquals I see the following constant: const double epsilon = 2.2204460492503131E-16; I am wondering what is the reason for this value, is it coming from Javascript, ...
0
votes
3answers
84 views

Unable To Find A Constructor

ScreenShot Of Error i have a json file which contains some data and i want to parse it but every time when i want to Deserialize Object it give me this error "Unable to find a constructor. A Class ...
-1
votes
2answers
36 views

Parsing Data From JSON To Windows Form

I am retrieving JSON from a web service and am getting this error: Error CS0030 Cannot convert type 'PokeForm.MoveInformation' to 'PokeForm.Move' This is the code I am using to query the web ...
1
vote
1answer
22 views

INotifyPropertyChanged and Deserialization

Given: public class MyClass : INotifyPropertyChanged { public List<string> _TestFire = new List<string>(); string _StringProp; public string StringProp { get ...
0
votes
2answers
26 views

Updating a specific item present in a JSON File using C#

In my application, I am using a json file to persist the details in my application to use it in offline situation. Suppose if I serialize and save the data in my application and later point I need to ...
1
vote
1answer
49 views

Dictionary<string, JToken> recursive search

I have DeserializeObject to a C# object however I have objects with dynamic object names so I have structured it like this: public class RootObject { public string name { get; set; } public ...
1
vote
1answer
56 views

How to fix InvalidCastException while using JsonConverter for an IList of Interfaces?

I am trying to create an abstraction layer for Json.NET deserialization using interfaces. To achieve this I use custom JsonConverter which works just fine, until interfaces are introduced. Following ...
0
votes
1answer
23 views

Consuming web api response is in encrpyted form but that response convert in json formate issue

enter image description hereenter image description hereenter image description hereenter image description here EmpInfo = JsonConvert.DeserializeObject<List<polygon>>(EmpResponse); ...
0
votes
1answer
42 views

Why is an assembly binding redirect required for this project?

I've used https://icanhasdot.net to analyze the NuGet dependencies of a sample project I've been experimenting with. Here are the results: The graph doesn't show specific versions, but I'm targeting ....
0
votes
0answers
32 views

Lowercase document in CosmosDB

I am trying to store a document in lowercase (both property name and value) in the CosmosDB. I just want to make it on the DocumentClient level. I found the below code to apply JsonSerializerSettings ...
1
vote
2answers
81 views

Return child objects from a JObject based on property value

I have some JSON as shown below. I would like to get all objects from it where the "type" is "Item". string json = @" { 'name': 'Object 1', 'content': { ...
2
votes
1answer
81 views

Using dot notation in a JSON property name (e.g. “payment.token”)

I am working on a script that has to make an API request. Currently, the object to send to the API looks like this: var request = new { amount = new { currency = amount.Currency, ...
-1
votes
1answer
65 views

how to add an empty array to a json payload?

Is it possible to add an array to a json payload? For example, let's say this is my payload: string json = @"{ 'channel': { 'title': 'Star Wars', 'link': '...
0
votes
2answers
73 views

Json deserialize Dictionary<key,value> return as null

Just a quick one! I have three object classes. public class Parent { public string name { get; set; } public Children child{ get; set; } } public class Children { public Dictionary<...
0
votes
2answers
53 views

response.Content.ReadAsStringAsync no reading all data

I have an azure function that calls a Rest API with basic authentication. The respone form the server is ok but I have a problem with only receiving partial data back from the response - some fields ...
0
votes
2answers
48 views

Json.net: converting in internal list ignoring the main class

I have a JSON string like this: [ { "A":"123", "B":"ABC"},{ "A":"345", "B":"CCC"},{ "A":"567", "B":"HGF"}] The target class for deserialization is: public class Response { public Item[] Items {...

http://mssss.yulina-kosm.ru