json.net

Getting “because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly” error when deserializing a Json object

与世无争的帅哥 提交于 2020-01-13 11:13:10
问题 Please help me. Where I am missing info? I need to deserialize the following JSON string. {"results":[{"series":[{"name":"PWR_00000555","columns":["time","last"],"values":[["1970-01-01T00:00:00Z",72]]}]}]} For this, I have defined my class: public class Serie { public Serie() { this.Points = new List<object[]>(); } [JsonProperty(PropertyName = "results")] public string results { get; set; } [JsonProperty(PropertyName = "series")] public string sries { get; set; } [JsonProperty(PropertyName =

Getting “because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly” error when deserializing a Json object

[亡魂溺海] 提交于 2020-01-13 11:11:14
问题 Please help me. Where I am missing info? I need to deserialize the following JSON string. {"results":[{"series":[{"name":"PWR_00000555","columns":["time","last"],"values":[["1970-01-01T00:00:00Z",72]]}]}]} For this, I have defined my class: public class Serie { public Serie() { this.Points = new List<object[]>(); } [JsonProperty(PropertyName = "results")] public string results { get; set; } [JsonProperty(PropertyName = "series")] public string sries { get; set; } [JsonProperty(PropertyName =

JSON.Net not calling CanConvert for collection item?

你。 提交于 2020-01-13 10:16:30
问题 I have a converter that I only want used when deserializing. So I set CanWrite to false, which works fine and everything Serializes fine. The Json string then contains an object graph within which there is a SantaClauseCollection with an array of SantaClause items and a $type indicating they are concrete type SantaClause. However, when it encounters a collection of SantaClaus while deserializing, it never calls CanConvert(I have a break point and see the SantaClausCollection, hit F5 to

Deserialize JSON not working with JSON.NET

放肆的年华 提交于 2020-01-13 10:08:41
问题 I have a problem with the following JSON when deserializing using JSON.NET. { "?xml": { "@version": "1.0", "@encoding": "utf-8" }, "Persons": { "Person": [{ "@Id": "1", "@Name": "John", "@Surname": "Smith" }, { "@Id": "2", "@Name": "John", "@Surname": "Smith", "Skills": { "Skill": [{ "@Id": "1", "@Name": "Developer" }, { "@Id": "2", "@Name": "Tester" }] } }] } } I'm using the following classes: public class RootObject { public Xml xml { get; set; } public Persons Persons { get; set; } }

Deserialize JSON not working with JSON.NET

99封情书 提交于 2020-01-13 10:06:50
问题 I have a problem with the following JSON when deserializing using JSON.NET. { "?xml": { "@version": "1.0", "@encoding": "utf-8" }, "Persons": { "Person": [{ "@Id": "1", "@Name": "John", "@Surname": "Smith" }, { "@Id": "2", "@Name": "John", "@Surname": "Smith", "Skills": { "Skill": [{ "@Id": "1", "@Name": "Developer" }, { "@Id": "2", "@Name": "Tester" }] } }] } } I'm using the following classes: public class RootObject { public Xml xml { get; set; } public Persons Persons { get; set; } }

Deserialize JSON not working with JSON.NET

a 夏天 提交于 2020-01-13 10:06:36
问题 I have a problem with the following JSON when deserializing using JSON.NET. { "?xml": { "@version": "1.0", "@encoding": "utf-8" }, "Persons": { "Person": [{ "@Id": "1", "@Name": "John", "@Surname": "Smith" }, { "@Id": "2", "@Name": "John", "@Surname": "Smith", "Skills": { "Skill": [{ "@Id": "1", "@Name": "Developer" }, { "@Id": "2", "@Name": "Tester" }] } }] } } I'm using the following classes: public class RootObject { public Xml xml { get; set; } public Persons Persons { get; set; } }

Json deserialize from wikipedia api with c#

一曲冷凌霜 提交于 2020-01-13 06:43:52
问题 I have a wikipedia api with json format. Now I want to get the extract information from this api. I want to make it dynamic for any wikipedia api. [My wikipedia api][1]. I got following information from jsontoCsharp namespace Json_deserialize { public class pageval { public int pageid { get; set; } public int ns { get; set; } public string title { get; set; } public string extract { get; set; } } public class Query { public Dictionary<string, pageval> pages { get; set; } } public class Limits

Method not found: 'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()'

China☆狼群 提交于 2020-01-12 19:32:01
问题 Locally my project runs fine but when I deploy on Azure using a web app, I get the following error when it starts: MissingMethodException: Method not found: 'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.Formatters.JsonOutputFormatter.get_SerializerSettings()'. SmartAdmin.Startup.<>c.b__13_7(MvcOptions options) I've tried this: services.AddMvc(options => { options.Filters.Add(new UserPreferencesLoaderAtrribute()); var jsonFormatter = (JsonOutputFormatter)options.OutputFormatters

How to convert a JToken

烂漫一生 提交于 2020-01-12 19:03:54
问题 I have a JToken with the value {1234} How can I convert this to an Integer value as var totalDatas = 1234; var tData = jObject["$totalDatas"]; int totalDatas = 0; if (tData != null) totalDatas = Convert.ToInt32(tData.ToString()); 回答1: You can use the JToken.ToObject<T>() method. JToken token = ...; int value = token.ToObject<int>(); 回答2: You should use: int totalDatas = tData.Value<Int32>(); 回答3: You can simply cast the JToken to int : string json = @"{totalDatas : ""1234""}"; JObject obj =

Using JsonConvert.DeserializeObject to deserialize a list of derived objects

假装没事ソ 提交于 2020-01-12 05:51:08
问题 I have this Object public class ConversationAPI { [JsonProperty(PropertyName = "lU")] public DateTime LastUpdated { get; set; } [JsonProperty(PropertyName = "m", TypeNameHandling = TypeNameHandling.All)] public List<Message> Messages { get; set; } } Which I send from the API as a json and I deserialize in my Client Application. The List<Message> Messages property contains either [Serializable] public class Message { [JsonProperty(PropertyName = "t")] public string Text { get; set; }