json.net

Azure Mobile App customizing json serialization

一个人想着一个人 提交于 2019-12-06 03:46:34
I can't seem to be able to customize JSON serialization in an Azure Mobile App. To avoid the complexity of my own code, I setup a new project from scratch. Visual Studio Community 2015 Update 2, Azure App Service Tools v2.9 (if that matters). New Project, Visual C#, Cloud, Azure Mobile App. In App_Start\Startup.MobileApp.cs this is what's in the template: public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); // Use Entity Framework Code First to create database

Build JSON Hierarchy from Structured Data

五迷三道 提交于 2019-12-06 03:41:10
C# | .NET 4.5 | Entity Framework 5 I have data coming back from a SQL Query in the form of ID,ParentID,Name. I'd like to take that data and parse it into a Hierarchical JSON string. So far it seems to be much more of a daunting task than it should be. Since I'm using Entity the data comes back nicely to me as an IEnumerable. Now I believe I just need some form of recursion, but I'm not quite sure where to start. Any help is appreciated. Data Returns as id parentId name 1 1 TopLoc 2 1 Loc1 3 1 Loc2 4 2 Loc1A Code is public static string GetJsonLocationHierarchy(long locationID) { using

Converting newtonsoft code to System.Text.Json in .net core 3. what's equivalent of JObject.Parse and JsonProperty

点点圈 提交于 2019-12-06 02:58:54
I am converting my newtonsoft implementation to new JSON library in .net core 3.0. I have the following code public static bool IsValidJson(string json) { try { JObject.Parse(json); return true; } catch (Exception ex) { Logger.ErrorFormat("Invalid Json Received {0}", json); Logger.Fatal(ex.Message); return false; } } I am not able to find any equivalent for JObject.Parse(json); Also what will be the attribute JsonProperty equivalent public class ResponseJson { [JsonProperty(PropertyName = "status")] public bool Status { get; set; } [JsonProperty(PropertyName = "message")] public string Message

ASP.NET WebAPI 2 deserializing JSON sets some nested objects to null

北战南征 提交于 2019-12-06 02:52:34
I am encountering an issue while sending some JSON from an AngularJS application to a ASP.Net WebAPI 2 back-end. What happens is that some properties from the incoming request are set to null during deserialization. Part of the request where the deserialization bug occurs: 12: {row: 9, column: 1, order: 13,…} column: 1 domainEntityProperty: {$id: "157", id: 2616,…} order: 13 renderType: {$id: "39", id: 1, class: "input"} row: 9 Above snippet is piece of the request that is being sent. It's a so called screen property being saved. The request has an array of these objects. The strange thing is

json.NET parsing issue with twitter API data

与世无争的帅哥 提交于 2019-12-06 02:45:44
问题 I have been using json.NET successfully in projects for some time now without any problems. Last night I ran into my first case where json.NET crashed trying to parse json data returned from what should be a reliable source: the twitter API. Specifically, this code causes the error: string sCmdStr = String.Format("https://api.twitter.com/1/users/lookup.json?screen_name={0}", sParam); string strJson = _oauth.APIWebRequest("GET", sCmdStr, null); JObject jsonDat = JObject.Parse(strJson); In my

deserialize json string depending on type

一曲冷凌霜 提交于 2019-12-06 02:36:34
Having json strings like this (I have no control over the publisher): { "TypeName": "Type1" } { "TypeName": "Type1" } Is this an acceptable way to deserialize the json strings dynamically?: public class DeserializationFactory { public static IPoco GetEvent(string jsonString) { var o = JObject.Parse(jsonString); IPoco poco = null; switch (o["TypeName"].ToString()) { case "Type1": poco = JsonConvert.DeserializeObject<Type1>(jsonString); break; case "Type2": poco = JsonConvert.DeserializeObject<Type2>(jsonString); break; } return poco; } } You can try with JsonSubtypes converter implementation

JSON.NET cannot handle simple array deserialization?

拥有回忆 提交于 2019-12-06 01:45:48
问题 I created a simple class with one field. class Test{int value;} If I use the "preserve references" feature and set it to "all" (i.e. both objects and arrays), then when I simply serialize an array of Test objects, it gets serialized as a JSON object with a special "$values" member with the array values, along with the expected "$id" property to preserve the array reference. That much is fine, but once again the whole thing breaks on deserialization. Stepping through the source code, I

Conditionally deserialize JSON string or array property to C# object using JSON.NET? [duplicate]

≯℡__Kan透↙ 提交于 2019-12-06 01:43:20
This question already has answers here : How to handle both a single item and an array for the same property using JSON.net (7 answers) Closed 3 years ago . I have a defined C# object based off a very complex JSON I'm getting from a third party API. Here's a piece of it: {"alarmSummary":"NONE"} The corresponding property in C# would be: public string alarmSummary {get; set;} And I would get this converted by using my typical JSONConvert from JSON.NET: var alarms = JSONConvert.DeserializeObject<MyClass>(jsonString); However, the API will put alarms in this format, as an array, and "NONE" when

Json.NET - deserialize directly from a stream to a dynamic?

≡放荡痞女 提交于 2019-12-06 01:41:40
问题 With a little help from the performance tips in the Json.NET docs, I put together a method for downloading/deserializing JSON from a remote resource: public async Task<T> GetJsonAsync<T>(string url) { using (var stream = await new HttpClient().GetStreamAsync(url)) { using (var sr = new StreamReader(stream)) { using (var jr = new JsonTextReader(sr)) { return new JsonSerializer().Deserialize<T>(jr); } } } } I'd like to have a non-generic version that returns a dynamic . Calling the above method

Deserializing json string with array of array with Json.NET

本小妞迷上赌 提交于 2019-12-06 01:37:13
问题 string json = @"{ 'symbol':'XX', 'column_names":["Date","Open","High","Low","Close","Volume"], 'data':[ ['2014-01-02',25.78,25.82,25.47,25.79,31843697.0], ['2013-12-31',25.81,26.04,25.77,25.96,22809682.0]]}"; public class DailyData { public string symbol { get; set; } public List<OneDay> data { get; set; } } public class OneDay { public DateTime date { get; set; } public double open { get; set; } public double high { get; set; } public double low { get; set; } public double close { get; set;