linq-to-json

JArray.Remove(JToken) does not delete

元气小坏坏 提交于 2020-01-21 10:00:27
问题 I have a JObject with a JSON like it: {"name" : "user1", "groups" : ["group 1", "group2"]} I would like to delete one group by the name. So I have a code like this: JObject userJson = JObject.Parse(user); JArray groups = userJson["groups"] as JArray; JToken group = new JValue (groupName); groups.Remove(group); However the method JArray.remove(Jtoken item) return false (that means that it couldn't be deleted). Here the information: https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json

JArray.Remove(JToken) does not delete

廉价感情. 提交于 2020-01-21 10:00:14
问题 I have a JObject with a JSON like it: {"name" : "user1", "groups" : ["group 1", "group2"]} I would like to delete one group by the name. So I have a code like this: JObject userJson = JObject.Parse(user); JArray groups = userJson["groups"] as JArray; JToken group = new JValue (groupName); groups.Remove(group); However the method JArray.remove(Jtoken item) return false (that means that it couldn't be deleted). Here the information: https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json

How to add “undefined” to a JObject collection - where is JToken/JValue.Undefined?

大兔子大兔子 提交于 2019-12-25 18:55:23
问题 When using Json.NET, I am trying to create a JSON structure dynamically using the "JSON to LINQ" support. In the following, jObject is a JObject and JObject.Add takes (string, JToken). However, I cannot find out how to add either an Undefined or a Null token - nor can I find out how to create JValues with the appropriate Null/Undefined type. string value = GetValue(); if (value == "undefined") { jObject.Add(key, /* how to add "Undefined" token? */); } else if (value == "null") { jObject.Add

Multiple table join using lambda/linq c# with DTO

泄露秘密 提交于 2019-12-25 02:58:55
问题 This really has me stumped. I have four tables in the database, and unfortunately the person who designed this table didn't create referential constraints. So, there is no navigation properties available. Four tables are: CiscoPhoneReport ApplicationSummary CSQActivityReport CallDistributionSummary The idea is that for each PhoneReportID in CiscoPhoneReport, there is one ApplicationSummary , three CSQActivityReport , and three CallDistributionSummary . I want the output as below in JSON

LINQ to Json data retrieval from polymorphic json

喜欢而已 提交于 2019-12-11 12:52:28
问题 I have a polymorphic json string. Here's what it looks like: { "?xml":{ "@version":"1.0", "@encoding":"UTF-8" }, "DataFeed":{ "@FeedName":"AdminData", "Issuer":[ { "name":"Apple", "symbol":"AAPL-O", "active":"1", "securities":{ "Security":{ "sedol":"B0XXF09", "coverage":{ "Coverage":{ "analyst":{ "@firstName":"Steve", "@lastName":"Jobs", "@rank":"1" } } }, "symbolMappingList":{ "SecuritySymbol":{ "symbolset":{ "id":"11", "symbol":"ISIN", "name":"ISIN", "rixmlName":"ISIN", "researchDirect":"S

Json.NET decimal precision loss

﹥>﹥吖頭↗ 提交于 2019-12-11 02:34:17
问题 I have an issue with deserializing decimal value. JObject.Parse("{\"available\":8777.831438322572000}") If I type this code in VS under debugger the result is "available": 8777.8314383225716 If I try this obj.Value<decimal>("available") the result is 8777.83143832257 Where am I wrong? What api methods should I use to get correct results? 回答1: The result of JObject.Parse("{\"available\":8777.831438322572000}") is a double . The second statement results in a decimal . The double has floating

JArray.Remove(JToken) does not delete

六月ゝ 毕业季﹏ 提交于 2019-12-06 16:10:11
I have a JObject with a JSON like it: {"name" : "user1", "groups" : ["group 1", "group2"]} I would like to delete one group by the name. So I have a code like this: JObject userJson = JObject.Parse(user); JArray groups = userJson["groups"] as JArray; JToken group = new JValue (groupName); groups.Remove(group); However the method JArray.remove(Jtoken item) return false (that means that it couldn't be deleted). Here the information: https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Linq_JArray_Remove.htm So tried to set the parameter like JToken group = new JValue (groupName); JToken

Why is there a JConstructor?

夙愿已清 提交于 2019-12-01 14:20:18
问题 Json.NET defines a JConstructor type. This is confusing, because (to the best of my knowledge) constructors are not part of JSON. I double-checked the JSON spec and browsed json.org but couldn't find anything. There also doesn't seem to be much documentation about this type anywhere on the web. Because Json.NET is so widely used (it is even cosigned by Microsoft) I assume there has to be some reasonable motivation for including this representation in the object model. The problem is, any

Can I LINQ a JSON?

六月ゝ 毕业季﹏ 提交于 2019-11-27 04:09:53
This is the JSON I get from a request on .NET: { "id": "110355660738", "picture": { "data": { "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1027085_12033235063_5234302342947_n.jpg", "is_silhouette": false } } } and I'd like to catch the field "url", using (maybe?) LINQ. I do many request as this, that differents a bit. So I won't to create a C# Class and deserialize it every time. Is it a way to extract a single field? Thank you! I4V No need for Linq, just use dynamic (using Json.Net ) dynamic obj = JObject.Parse(json); Console.WriteLine((string)obj.picture.data.url); Linq

Can I LINQ a JSON?

独自空忆成欢 提交于 2019-11-26 11:05:33
问题 This is the JSON I get from a request on .NET: { \"id\": \"110355660738\", \"picture\": { \"data\": { \"url\": \"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1027085_12033235063_5234302342947_n.jpg\", \"is_silhouette\": false } } } and I\'d like to catch the field \"url\", using (maybe?) LINQ. I do many request as this, that differents a bit. So I won\'t to create a C# Class and deserialize it every time. Is it a way to extract a single field? Thank you! 回答1: No need for Linq, just