json.net

Postgres json_agg includes column header - Incorrect JSON?

只谈情不闲聊 提交于 2020-02-04 14:37:53
问题 Follwoing this post, I have a SQL query that returns the following table: team (json) "{"Name":"TeamA","Players":[{"Name":"CCC"},{"Name":"BBB"}]}" "{"Name":"TeamB","Players":[{"Name":"AAA"},{"Name":"DDD"}]}" I need to aggregate this into JSON to use in my app. I'm using the following: SELECT json_agg(u) FROM (SELECT DISTINCT ON (t.team->>'Name') t.team FROM matches m, json_array_elements(m.match->'Teams') t(team) ORDER BY t.team->>'Name', m.id DESC) AS u Which returns: "[{"team":{"Name":

JSON.NET serialization of System.Drawing.Color with TypeNameHandling

六月ゝ 毕业季﹏ 提交于 2020-02-04 10:35:07
问题 I want to serialize a Dictionary<string, object> that may contain System.Drawing.Color values or other types as values. I create a serializer with TypeNameHandling.Auto , and this works for most classes, but not Color . Example code: (DotNetFiddle: https://dotnetfiddle.net/UvphQO) public class Program { class A { } class B { } public static void Main() { Dictionary<string, object> dict = new Dictionary<string, object>(); dict["Foo"] = new A(); dict["Bar"] = new B(); dict["Baz"] = new object()

Easiest way to parse a Javascript date in C#?

送分小仙女□ 提交于 2020-02-04 05:13:12
问题 I see that JSON.NET has a DateTime converter: string javascriptJson = JsonConvert.DeserializeObject(entry, new JavaScriptDateTimeConverter()); However I don't have a JSON object, I simply have a string: /Date(1276146000000-0500)/ I could create an object, add the date, then parse it, but this seems common enough that there should be a way to do this in a single line. Is there anything out there? 回答1: The quotes around the date string are required. Also, the returned value is a DateTime , not

Can't make MVC4 WebApi include null fields in JSON

戏子无情 提交于 2020-02-02 02:37:29
问题 I'm trying to serialize objects as JSON with MVC4 WebAPI (RTM - just installed VS2012 RTM today but was having this problem yesterday in the RC) and I'd like for all nulls to be rendered in the JSON output. Like this: [{"Id": 1, "PropertyThatMightBeNull": null},{"Id":2, "PropertyThatMightBeNull": null}] But what Im getting is [{"Id":1},{"Id":2}] I've found this Q/A WebApi doesnt serialize null fields but the answer either doesn't work for me or I'm failing to grasp where to put the answer.

Why max digits with decimal in JavaScript are only 16

可紊 提交于 2020-01-30 11:58:08
问题 I came across this issue a while back when I was testing some HTML forms. The Maximum number of digits in JavaScript Number with a decimal point is only 16 I have tried the following var x = 12345678912345.6789 x is 12345678912345.68 - 16 Digits only var x = 123456789123.6789 x is 123456789123.6789 - 16 Digits only new Number(12345678912345.6789) 12345678912345.68 - 16 Digits only new Number(123456789123.6789) 123456789123.6789 - 16 Digits only if you count the total digits, they are 16. If

Why max digits with decimal in JavaScript are only 16

天涯浪子 提交于 2020-01-30 11:56:05
问题 I came across this issue a while back when I was testing some HTML forms. The Maximum number of digits in JavaScript Number with a decimal point is only 16 I have tried the following var x = 12345678912345.6789 x is 12345678912345.68 - 16 Digits only var x = 123456789123.6789 x is 123456789123.6789 - 16 Digits only new Number(12345678912345.6789) 12345678912345.68 - 16 Digits only new Number(123456789123.6789) 123456789123.6789 - 16 Digits only if you count the total digits, they are 16. If

How to prevent “Date & Time” conversion while converting a json string to XML doc

梦想的初衷 提交于 2020-01-30 09:32:11
问题 I want to convert a JSON response to an equivalent XML document but while doing so, I also want to preserve current date and time format along with the offset e.g., DateTime in JSON is "2019-10-25T07:00:00-05:00" and after conversion I want it to remain the same. But after conversion into XML, the DateTime value becomes "2019-10-25T08:00:00-04:00" I tried to search about it in Microsoft docs but I didn't find my answer for the following questions: How to determine the time zone of a given

How to add a new JProperty to a JSON based on path?

僤鯓⒐⒋嵵緔 提交于 2020-01-30 05:17:29
问题 There is a large JSON file (about a thousand lines). The task is to update existing JProperties, or add new JProperties in a specific location in the structure. The location of the new texts are based on the JToken.Path property. For example, this is the start of the JSON: "JonSnow": { "Direwolf": { "Name": "Ghost", "Color": "White", } } "DanaerysTargaryen": { "Dragons": { "Dragon1": { "Name": "Drogon", } } "Hair": { "Color": "White" } } Now the JSON must be updated using a given list of

Deserialize json with c# with random root names

我的梦境 提交于 2020-01-30 04:59:09
问题 I have a json file which has random names in roots but same structure in child elements. I would like to get all the child elements in an array or a list. Sample json file : { "-LeHl495vL6vh-8CaLbD":{ "apiKey":"sr-tr-137-beea04e44cb452ba0da0ca090b7e61b4ec6ffc69" }, "-LeHl6jrhUEMb7slZcpB":{ "apiKey":"sr-tr-137-aef7a23095c0c7baef1ef681bdd8bf9756ac2a17" } } I have tried these classes but could not do it. public class RequestedReport { public Dictionary<string, List<ReportData>> ReportDatas { get

Json.NET + VerificationException Operation could destabilize the runtime

孤者浪人 提交于 2020-01-30 04:12:31
问题 I am getting the "Operation could destablize the runtime exception". I goggled quite a bit, looks like exception has to do with conflicting assemblies being loaded at runtime. So, here are couple of things the same source code works in my colleagues machine. I looked and searched for each reference to NewtonSoft.Json.dll and it seems like its coming from a same assembly. (I think this would not be a problem as it is working in other people machine). I am using Raven which references