json.net

Cosmos DB Newtonsoft Deserialization Issue

断了今生、忘了曾经 提交于 2019-12-10 11:44:53
问题 I am having a strange issue with CosmosDb unable to deserialise my class. The error I am getting is Could not create an instance of type TestApp.Entities.IVisitItem. Type is an interface or abstract class and cannot be instantiated I have the following code in my startup class JsonConvert.DefaultSettings = () => new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }; And when I look in the Data Explorer and look at my document, I can see that the type information is saved

Using Json.NET, deserialize to a property but has a numeric name

老子叫甜甜 提交于 2019-12-10 11:43:58
问题 Got the Json { "commentary": null, "crimes": { "2010-12": { "anti-social-behaviour": { "crime_rate": "0.08", "crime_level": "below_average", "total_crimes": 47 } } } }}" Using Json.net to deserialize it, well restsharp which uses json.net. but it wont map to my classes as I cannot put a property called 2010-12 as the .net framework does not allow this. Any thoughts? Currently i got public class neighbourhoodcrimes { public String commentary { get; set; } public crimes crimes { get; set; } }

C# Json Convert any dynamic object to key value pairs

落爺英雄遲暮 提交于 2019-12-10 11:41:43
问题 I am writing a tool that will take an inbound Json object, and convert it to key-value records (sometimes called flattening, maybe). The aim is to avoid the tool breaking if it gets a very large or very nested Json object, so I would like to avoid recursion. An example object might be like this (below), containing nested arrays, empty values, you name it, literally any legal json... { "firstName": "John", "lastName": "Smith", "isAlive": true, "age": 25, "address": { "streetAddress": "21 2nd

Convert Json.NET objects to conventional .NET objects without knowing the types [duplicate]

匆匆过客 提交于 2019-12-10 11:25:36
问题 This question already has answers here : How do I use JSON.NET to deserialize into nested/recursive Dictionary and List? (5 answers) Closed 3 years ago . How do I convert Json.NET objects to conventional .NET types ( JArray of string to List<string> , JTokenType=Integer to int , etc.)? I have found little besides suggestions to use AutoMapper or JToken.ToObject<T> . This is good advice when the JSON structure is known at compile time, but I can't create a class to represent unknown data, or

How can I deserialize a JSON object that uses unspecified and variable property names

流过昼夜 提交于 2019-12-10 11:19:35
问题 I have a JSON response (which I have no control over) similar to this: {"response":{ "a" : "value of a", "b" : "value of b", "c" : "value of c", ... }} Where: "a", "b", "c" are unknown names upfront. The number of items can vary. All I need at the end is an array of strings for all the values. Keeping the names is a bonus (Dictionary?) but I need to browse values by the order in which they appear. How would you achieve this using JSON.NET? 回答1: You can use the JObject class from the

null value exception thrown when deserializing null value JSON.net

早过忘川 提交于 2019-12-10 11:13:17
问题 Hi Friends I am trying to deserialize a hidden control field into a JSON object the code is as follows: Dim settings As New Newtonsoft.Json.JsonSerializerSettings() settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of testContract)(txtHidden.Text, settings) But I am getting the following exception. value cannot be null parameter name s: I even added the following lines but it still does not work out. Please help.

Can I set a custom JsonSerializer to RestSharp RestClient

跟風遠走 提交于 2019-12-10 10:55:57
问题 I'm using the custom JsonSerializer as mentioned in the Readme file in the RestSharp package. Up until now I added the custom serializer to each request: RestRequest request = new RestRequest("scans", Method.POST); request.JsonSerializer = new MyCustomJsonSerializer(); But the read me file mentained I can add it straight to the restclient: There is one breaking change: the default Json Serializer is no longer compatible with Json.NET. To use Json.NET for serialization, copy the code from

How to send Json Data from Aspx page

爷,独闯天下 提交于 2019-12-10 10:46:52
问题 I tried to use TokenInput Jquery for multiple value autocomplete where it requires the JSON response as input data http://loopj.com/jquery-tokeninput/ I am using ASPX page as source <script type="text/javascript" > $(document).ready(function() { $("#txtTest").tokenInput("Complete.aspx", { theme: "facebook" }); }); </script> Edited From Here Question: How to provide the JSON data from a aspx page in the desired format as i have datatable with values according to Querystring from Complete.aspx

Deserializing dictionary with derived types using NewtonSoft's Json library

对着背影说爱祢 提交于 2019-12-10 10:34:56
问题 Given the following class structure, which includes a dictionary of derived objects, how can I serialize and deserialize using NewtonSoft’s Json library? When I deserialize, I am getting an exception. It looks like it is having issues reconstituting the dictionary. [JsonObject(MemberSerialization.OptIn)] public class GameObject { [JsonProperty] public string Id { get; set; } [JsonProperty] public string Name { get; set; } [JsonProperty] public ConcurrentDictionary<string, Component>

How to deserialize a JSON array with nested arrays of objects

怎甘沉沦 提交于 2019-12-10 10:31:11
问题 I have a JSON string as follows and want to deserialize it: [[{"campaignId":201410018,"programCode":"54321"}],[{"campaignId":201410018,"programCode":"54321"}]] I have created some classes as follows: public class Rootclass { public List<JSONResponse> rootClass { get; set; } } public class JSONResponse { public int campaignId { get; set; } public string programCode { get; set; } } I am calling this JSON.NET method to deserialize the JSON: List<Rootclass> myDeserializedObjList = (List<Rootclass