json.net

System.MissingMethodException: Error while deserialization of json array

岁酱吖の 提交于 2019-12-20 02:27:33
问题 I am getting error while deserializing jsonString. Error is Type 'oodleListingsUser' is not supported for deserialization of an array. My code of deserialization is string jsonString = new WebClient().DownloadString("http://api.oodle.com/api/v2/listings?key=TEST&region=region_value&category=category_value&format=json"); JavaScriptSerializer ser = new JavaScriptSerializer(); jsonOodleApi p = ser.Deserialize<jsonOodleApi>(jsonString); My class defination of jsonOodleApi is public class

Deserializing MandrillApp Webhook response

我只是一个虾纸丫 提交于 2019-12-20 02:14:03
问题 MandrillApp API supposedly sends a JSON-encoded array of the messages with the mime type application/x-www-form-urlencoded . The problem I have encountered is that the data received looks like: mandrill_events=%5B%7B%22event%22%3A%22send%22 %2C%22msg%22%3A%7B%22ts%22%3A136510999...etc Url decoded it is: mandrill_events=[{"event":"send","msg":{ "ts":1365109999,"subject"...etc I try to deserialize this string into a class that represents the JSON data but the JSON.NET deserializer spits out an

Querying and Filtering Array of JObjects with Linq

时光毁灭记忆、已成空白 提交于 2019-12-20 01:52:12
问题 I suppose this is another entry in my series of questions, but I'm stuck again. This time, I'm having trouble working with a JArray of JObjects and determining the Property.Value type for each element in the JArray... My code is here: https://dotnetfiddle.net/bRcSAQ The difference between my previous questions and this question is that my outer Linq query gets both JObject and JArray tokens, so that's why I have an if (jo is JObject) at Line 40 and a if (jo is JArray) at Line 48. Once I know

HttpClient PostAsJsonAsync incompatible with Newtonsoft.Json

只愿长相守 提交于 2019-12-20 01:08:39
问题 Something I have just picked up in my winforms app My app does an http call to a web Api service as follows HttpClient _client = new HttpClient(); _client.Timeout = new TimeSpan(0, 3, 0); _client.BaseAddress = new Uri("http://Myserver/MyApp"); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = _client.PostAsJsonAsync("api/Addin", newObject).Result; Nothing fancy, but as soon as you install Newtonsoft.Json (V6.0.3)

Set JSON attribute by path

我只是一个虾纸丫 提交于 2019-12-20 01:00:13
问题 Is there a way to set an attribute by the path, using Json.NET? JObject o = JObject.Parse(@"{ 'CPU': 'Intel', 'Drivers': { 'Mouse': 'HPQ', 'VideoCard' : 'NVidia' } }"); //something like that o.SetByPath("Drivers.VideoCard") = "Intel"; Is it possible? By the way, I know that I can do this: o["Drivers"]["VideoCard"] = "Intel"; but that's not what I'm looking for. 回答1: The JObject.SelectToken and JToken.Replace methods can be used here to achieve essentially the same effect. static void Main

Json.Net serializing the class name instead of the internal properties

ε祈祈猫儿з 提交于 2019-12-19 20:47:26
问题 This is the code: public class ParameterDictionary : Dictionary<HydroObjectIdentifier, string> { public void WriteToJson(string jsonFilePath) { string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, formatting: Newtonsoft.Json.Formatting.Indented); System.IO.File.WriteAllText(jsonFilePath, json); } } public struct HydroObjectIdentifier { public string Name { get; set; } public string TypeName { get; set; } public HydroObjectIdentifier(string name, string typeName) { this.Name = name;

Newtonsoft.JSON serializeobject returns empty JSON string [duplicate]

♀尐吖头ヾ 提交于 2019-12-19 19:57:34
问题 This question already has answers here : JsonConvert.SerializeObject always return {} in XamarinForms (2 answers) Closed last year . Everyone got this question a lot, and I tried almost everything but none of it works for me. So I am developing in Xamarin.Forms and is about to send my data to the server. I have this class: public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public string BirthDate { get; set; } public string Password { get; set;

Why do I get a JsonReaderException with this code?

半城伤御伤魂 提交于 2019-12-19 17:52:10
问题 I've got this code to try to open a .json file and read it: [Route("{unit}/{begindate}")] public string Get(string unit, string begindate) { string _unit = unit; string _begindate = String.Format("{0}01", PlatypusWebReportsConstsAndUtils.HyphenizeYYYYMM(begindate)); string appDataFolder = HttpContext.Current.Server.MapPath("~/App_Data/"); // semi-hardcoded file name for now string jsonFilename = string.Format("PoisonToe_{0}_{1}.json", _unit, _begindate); string fullPath = Path.Combine

Why does Json.NET not include $type for the root object when TypeNameHandling is Auto?

◇◆丶佛笑我妖孽 提交于 2019-12-19 17:34:14
问题 When I set Json.NET to serialize with TypeNameHandling set to TypeNameHandling.Auto, it correctly sets $type for child properties of an object but does not do so for the root object being serialized. Why? Please consider the following repro: public class Animal { public Animal[] Offspring { get; set; } } public class Dog : Animal {} Animal fido = new Dog { Offspring = new Animal[] { new Dog() } }; var json = JsonConvert.SerializeObject(fido, new JsonSerializerSettings { TypeNameHandling =

Why does Json.NET not include $type for the root object when TypeNameHandling is Auto?

∥☆過路亽.° 提交于 2019-12-19 17:34:12
问题 When I set Json.NET to serialize with TypeNameHandling set to TypeNameHandling.Auto, it correctly sets $type for child properties of an object but does not do so for the root object being serialized. Why? Please consider the following repro: public class Animal { public Animal[] Offspring { get; set; } } public class Dog : Animal {} Animal fido = new Dog { Offspring = new Animal[] { new Dog() } }; var json = JsonConvert.SerializeObject(fido, new JsonSerializerSettings { TypeNameHandling =