json.net

Extract Values from JObject

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 16:29:55
问题 I'm trying to extract some values from a Json but I have problems with the data between [ ] { attrib1: ""es-BO"", attrib2: 2, Segment: [ { inAttrib1: ""value1"", inAttrib2: ""value2"", inAttrib3: ""value3"" }] } for the first values I'm using: string attrib1 = request.GetValue("attrib1").Value<string>(); . . . but when I'm trying to do: string inAttrib1 = request.GetValue("inAttrib1").Value<string>(); doesn't work...what can I do?, or exists another way to do the same 回答1: The data between

How to resolve this conflict of two JSON.net existing?

送分小仙女□ 提交于 2019-12-08 16:21:21
问题 I updated json.net in all projects in my solution and after I get this error: The type 'Newtonsoft.Json.JsonConvert' exists in both '\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll' and 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll Why is it trying to load json.net from the Blend folder and how do I get around this issue? Thanks. 回答1: In my case, the problem was that there were two references to two different versions of Newtonsoft.Json.dll in my

Serializing F# Option types

邮差的信 提交于 2019-12-08 16:09:54
问题 Consider the F# fragment below: type MyType = { CrucialProperty: int OptionalProperty: string option } let first = { CrucialProperty = 500; OptionalProperty = Some("Hello")} let second = { CrucialProperty = 500; OptionalProperty = Some(null)} let third = { CrucialProperty = 500; OptionalProperty = None} I wish to do serialize this type using JSON.NET so I get the following strings respectively for the cases described above: {"CrucialProperty":500,"OptionalProperty":"Hello"} {"CrucialProperty"

Can Json.NET serialize to stream with Formatting?

℡╲_俬逩灬. 提交于 2019-12-08 15:55:13
问题 When using Json.NET library, you can specify formatting when you are serialising to string, but I can't find this option when serialising directly to stream. Am I missing something? The code for the two serialisation methods is as follows: public static string Serialize(MyObject obj) { JsonSerializerSettings settings = GetJsonSerializerSettings(); return JsonConvert.SerializeObject(obj, Formatting.Indented, settings); } public static void SerializeToStream(MyObject obj, Stream stream) { var

Compare two JObjects or JArray

♀尐吖头ヾ 提交于 2019-12-08 15:49:54
问题 I have this WPF application which gets data from REST web service and returns a JSON data. Then this data will be converted to xml. This xml file later will be converted back to JSON to be compared with new JSON data from REST web service calling same function. How do I do this? Here is a sample of what I did: HTTPGet req = new HTTPGet(); req.Request("http://restservice//function"); string str= req.ResponseBody; StringBuilder xmlTemplate = new StringBuilder("{\"?xml\":{\"@version\": \"1.0\",\

Parsing json in C# without knowing indexes

杀马特。学长 韩版系。学妹 提交于 2019-12-08 15:47:54
问题 I want to parse this piece of JSON in C# with JSON.NET, but I don't know how to go about it. Json: { "success":true, "rgInventory":{ "967633758":{ "id":"967633758", "classid":"23973033", "instanceid":"11040671", "amount":"1", "pos":1 }, "302756826":{ "id":"302756826", "classid":"15", "instanceid":"11041143", "amount":"1", "pos":2 },... } } Full Json: http://steamcommunity.com/id/jessecar/inventory/json/440/2/?trading=1 I need to get the elements of each "rgInventory" child, but I can't make a

Looking for demos, sample code and tutorial about JSON.NET [closed]

泄露秘密 提交于 2019-12-08 15:42:41
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I am looking for demos, sample code and tutorial about JSON.NET. I would prefer demonstrations ready to use. 来源: https://stackoverflow

Convert a Tree Class into a simpler Tree class and Serialize to Json maintaining structure

强颜欢笑 提交于 2019-12-08 15:02:50
问题 ok, so i have a class similar to this: public class Channel { public Guid Guid{get;set;} public string Title{get;set;} /* GOT A LOT MORE PROPERTIES IN THIS SPACE */ public Guid Parent {get;set;} public List<Channel> Children{get;set;} } i also have a List<Channels> (with a total of about 650 Channels ) the ROOT channel contains about 6 channels and each of the channels contains, children and so on. as you see in the code of Channel there are a lot of other properties, which i don't want to

Why does JsonConvert.DeserializeObject not use the specified JsonConverter?

本秂侑毒 提交于 2019-12-08 14:11:12
问题 I've written a custom JsonConverter that I can assign to JsonSerializerSettings and use with the generic override of JsonConvert.DeserializeObject just fine: var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, Converters = new List<JsonConverter>() { new MyConverter() } }; var x = JsonConvert.DeserializeObject<MyType>(input, settings); The serialized Json was built also using TypeNameHandling.All so it contains type information in a $type field. In some

Efficiently get full json string in JsonConverter.ReadJson()

纵然是瞬间 提交于 2019-12-08 13:50:17
问题 How can I efficiently get full json string in JsonConverter.ReadJson() ? I can do: public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var json = JObject.Load(reader).ToString(Formatting.None); However that seems very inefficient as I serialize and deserialize for no reason Any better way ? 回答1: ReadJson() must fully parse the JSON being read so that the JSON is confirmed to be well-formed and the JsonReader is correctly