json.net

Why doesn't reference loop detection use reference equality? [closed]

白昼怎懂夜的黑 提交于 2019-12-17 14:57:29
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . When serializing the object below, Json.Net detects a self-referencing loop and throws an exception. The class has two important features: it has a self-referential property, Child it overrides Equals() and GetHashCode() public class Foo { public int Value { get; set; }

Newtonsoft JSON.Net SelectToken Issue

孤街醉人 提交于 2019-12-17 14:55:25
问题 I have the following query and the sample JSON. I try it on "http://jsonpath.com/" it works as expected. If I try it in VisualStudio it returns no results. $.Items.Services[?(@.Name == 'Another Service')].Url Here's the JSON: { "Items": { "Resource": { "Id": "12345" }, "Services": { "service1": { "Name": "My First Service", "Type": "WS", "Url": "https://server1/service1" }, "service2": { "Name": "Another Service", "Type": "WS", "Url": "https://server2/service2" } } } } And the sample code:

Custom deserializer only for some fields with json.NET

≡放荡痞女 提交于 2019-12-17 13:54:57
问题 I'm trying to deserialize some JSON: { "a":1, "b":25, "c":"1-7", "obj1":{ "a1":10, "b1":45, "c1":60 }, "obj2":[ { "a2":100, "b2":15, "c2":50 }, { "e2":"1,2,5-7", "f2":"1,3-5", "a2":25 } ] } I want to find a way to define a custom de-serialization only for some fields. In the following code, I separated the fields that need some attention (custom processing) and the ones that could be done automatically somehow. Is it possible to automatically deserialize the "normal" fields? (that don't need

Is there a library to read JSON in C# on Windows Mobile? [closed]

心不动则不痛 提交于 2019-12-17 13:53:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am trying to find a library to parse JSON on C# on Windows Mobile (working with Visual Studio 2005). The libraries that I have found that allow me to parse JSON in C# (litjson and Jayrock) don't work on Windows Mobile, they require classes that are not present in the .NET compact framework. Is there any

JSonNet boolean serialization

我与影子孤独终老i 提交于 2019-12-17 11:45:11
问题 Quick question: In JSONNet - how do i get bool true/false to serialize as bool 1/0 I can see how we handle null values and all that just cant seem to find how to do this. is this possible? 回答1: You can implement a custom converter like this: [TestFixture] public class CustomJsonSerialization { [Test] public void Test() { string serializeObject = JsonConvert.SerializeObject(true, new BoolConverter()); Assert.That(serializeObject, Is.EqualTo("1")); var deserializeObject = JsonConvert

Newtonsoft ignore attributes? [duplicate]

偶尔善良 提交于 2019-12-17 10:56:12
问题 This question already has answers here : Can I optionally turn off the JsonIgnore attribute at runtime? (3 answers) Closed last year . I am currently using the same C# DTOs to pull data out of CouchDB, via LoveSeat which I am going to return JSON via an ASP MVC controller. I am using the NewtonSoft library to seralise my DTOs before sending them down through the controller. However, as CouchDB also uses NewtonSoft it is also respecting the property level NewtonSoft attributes such as

How to access elements of a JArray

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 10:48:10
问题 I have the following Json gotten from Twitter + token {[ { "trends": [ { "name": "Croke Park II", "url": "http://twitter.com/search?q=%22Croke+Park+II%22", "promoted_content": null, "query": "%22Croke+Park+II%22", "events": null }, { "name": "#twiznight", "url": "http://twitter.com/search?q=%23twiznight", "promoted_content": null, "query": "%23twiznight", "events": null }, { "name": "#Phanhattan", "url": "http://twitter.com/search?q=%23Phanhattan", "promoted_content": null, "query": "

accessing all items in the JTOKEN, json.net

馋奶兔 提交于 2019-12-17 10:39:12
问题 I have a json block like this: { "ADDRESS_MAP":{ "ADDRESS_LOCATION":{ "type":"separator", "name":"Address", "value":"", "FieldID":40 }, "LOCATION":{ "type":"locations", "name":"Location", "keyword":{ "1":"LOCATION1" }, "value":{ "1":"United States" }, "FieldID":41 }, "FLOOR_NUMBER":{ "type":"number", "name":"Floor Number", "value":"0", "FieldID":55 }, "self":{ "id":"2", "name":"Address Map" } } } How can I get all the key items that this token includes. For example from the above code I want

JSON.Net Xml Serialization misunderstands arrays

百般思念 提交于 2019-12-17 10:37:08
问题 I have some autogenerated xmls where some parts of the xml may have multiple rows and some may not. The result is that if there is one row a single json node is returned and if I have multiple rows an array with json nodes are returned. The xmls may look like this <List> <Content> <Row Index="0"> <Title>Testing</Title> <PercentComplete>0</PercentComplete> <DueDate/> <StartDate/> </Row> </Content> </List> Or with multiple rows <List> <Content> <Row Index="0"> <Title>Update Documentation</Title

Selectively use default JSON converter

拟墨画扇 提交于 2019-12-17 10:00:10
问题 I use the following in my Web API project's Startup.cs to JSON-serialize Enums into strings: // Configure JSON Serialization var jsonSerializationSettings = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings; jsonSerializationSettings.Formatting = Newtonsoft.Json.Formatting.None; jsonSerializationSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); This is to avoid decorating every Enum property with [JsonConverter(typeof