json.net

How to deserialize Json String dynamically

こ雲淡風輕ζ 提交于 2019-12-04 06:26:59
问题 I have consume Survey data via SSE Stream that gives me each persons answers line by line with this format for Survey X : {"data":["4482359","12526","5","5","","Yes, that is right","1"]} I read it into a List(of String) using Streamreader Dim sr As StreamReader = New StreamReader(stream) Dim myList As List(Of String) = New List(Of String) While sr.Peek >= 0 myList.Add(sr.ReadLine()) End While Now I want to deserialize the strings so I get the entries into properties of a class (let us call it

Deserializing json string with array of array with Json.NET

霸气de小男生 提交于 2019-12-04 06:22:21
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; } public double volume { get; set; } } DailyData dd = JsonConvert.DeserializeObject<DailyData>(json);

JSON.Net - cannot deserialize the current json object (e.g. {“name”:“value”}) into type 'system.collections.generic.list`1

隐身守侯 提交于 2019-12-04 06:05:11
I have a JSON like { "40": { "name": "Team A vs Team B", "value": { "home": 1, "away": 0 } }, "45": { "name": "Team A vs Team C", "value": { "home": 2, "away": 0 } }, "50": { "name": "Team A vs Team D", "value": { "home": 0, "away": 2 } } } So it's kind of list of matches. And I have the class to deserialize it into: public class Match { [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "value")] public Value Values { get; set; } } public class Value { [JsonProperty(PropertyName = "home")] public int Home { get; set; } [JsonProperty

Newtonsoft.Json.dll conflicts between Visual Studio 12.0 Blend and MVC 5 web project VS 2013

南楼画角 提交于 2019-12-04 05:56:46
I have a asp.net mvc 5 project in VS2013, I updated the nuget packages of everything to latest then I run into this error Error 2 The type 'Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver' exists in both 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll' and '{path to my project}\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll' Does anyone else run into this. I got that error because I had an additional <ItemGroup> <Reference Include="Newtonsoft.Json"> <HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll<

How to serialize an ISerializable object into SOAP or Json or Xml

China☆狼群 提交于 2019-12-04 05:55:37
问题 I have a complex object which is ISerializable and i want to serialize it into an XML document (node that i rather to not change the source code and add XML serialization attribute stuff). ISerializable works fine with BinaryFormatter, but there is no standard way to serialize it into XML or Json. The Json.NET library does support for serializing a ISerializable object into json, but there is a very small problem with that implementation, and that is the serializable constructor of class

JSON.NET cannot handle simple array deserialization?

北城以北 提交于 2019-12-04 05:43:49
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 discovered that simply because the test for " IsReadOnlyOrFixedSize " is true, it sets a flag "

How to serialize a model with all validation attributes from the individual properties?

不问归期 提交于 2019-12-04 05:42:31
Context: creating a jsonP service with mvc controller methods which provides a definition of formfields including all validation rules. My problem is that I do not know how to serialize the validation attributes. I prefer the validation attributes in the same format as they are serialized by Razor when using unobtrusive validation in regular Mvc views. For serializing to json I use NewtonSoft.Json (4.0.2). Example of model: public class Profile{ [Required(ErrorMessage="This field is required.")] [StringLength(25, ErrorMessage="Max 25 chars.")] public string Firstname{get;set;} } Example of

How to compare two Json objects using C#

耗尽温柔 提交于 2019-12-04 05:40:26
I have two Json objects as below need to be compared. I am using Newtonsoft libraries for Json parsing. string InstanceExpected = jsonExpected; string InstanceActual = jsonActual; var InstanceObjExpected = JObject.Parse(InstanceExpected); var InstanceObjActual = JObject.Parse(InstanceActual); And I am using Fluent Assertions to compare it. But the problem is Fluent assertion fails only when the attribute count/names are not matching. If the json values are different it passes. I require to fail when values are different. InstanceObjActual.Should().BeEquivalentTo(InstanceObjExpected); For

JsonConvert.SerializeObject passes custom type properties to parent types Equals(object) method

被刻印的时光 ゝ 提交于 2019-12-04 05:33:54
问题 I'm seeing some weird behavior serializing with Json.NET v6.0.5 for objects that override the Equals method and have reference type properties, aside from string. public class TestObject { public ChildObject CustomTypeProperty { get; set; } public List<string> ListProperty { get; set; } public List<ChildObject> ListCustomProperty { get; set; } public string StringProperty { get; set; } public int IntProperty { get; set; } public override bool Equals(object obj) { Console.WriteLine(obj.GetType

Why is the Json.NET Parser automatically localizing the dates it's parsing?

限于喜欢 提交于 2019-12-04 05:31:25
问题 I'm running into problems with the Json.NET Parser. According to the documentation, simply using ToString() with no special converters should leave the Json unaltered. My Json string, however, is getting modified is having its date automatically localized, and it's causing all sorts of problems for me. For example, when I feed it the following string: { "_type": "Basic", "id": "44902a0f-7842-3a2d-83bf-a874ce0b47a1", "description": "TestBasicDescription", "participation": 1.000000000000000,