In Josh Smith's MVVM demo he's uses a ListView with a ListViewItem style like this: <Style x:Key="CustomerItemStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" /> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="I
在Josh Smith的MVVM演示中,他使用了一个带ListViewItem风格的ListView,如下所示: <Style x:Key="CustomerItemStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" /> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="ItemsControl.A
I'm working on a Roslyn extension to warn against unprotected .Value accesses of Nullable<T> values. This provides the following behaviour: This extension already sort of works, but the code to test if an access is "safe" is sort of a hack. I now simply walk the syntax tree, looking for if statements. This approach is quite ugly and produces a bunch of invalid warnings.
我正在研究一个Roslyn扩展,以警告未受保护的.Value对Nullable<T>值的访问。 这提供了以下行为: 这个扩展已经有些作品了,但测试访问是否“安全”的代码有点像黑客。 我现在走纯粹的语法树,寻找if声明。 这种方法非常难看,并产生一堆无效的警告。 以下是访问x.Value应该安全的一些示例: int y; int? x = foo(); y = x != null ? x.Value : 42; if (x > 4) y = x.Value; if (x != null && someE
I'm trying to use Json.NET to serialise a class for transfer via an http request. This is a client server test program that shares some common class files. Those files are an interface ( ITestCase ) and the implementations of this interface ( TestPicture , TestVideo ). Serialising and deserialising testCase below within the same application works fine, presumably because the Json.NET code
我试图使用Json.NET来通过http请求序列化传输类。 这是一个共享一些常用类文件的客户端服务器测试程序。 这些文件是一个接口( ITestCase )和这个接口的实现( TestPicture , TestVideo )。 在同一个应用程序中对下面的testCase序列化和反序列化是可行的,大概是因为Json.NET代码都包含在一个程序集中。 当我连载testCase ,发送到服务器,然后尝试反序列化,我得到错误 "Error resolving type specified in JSON
This is my first little project on C# and JSON. I'm asked to parse a JSON file into the following: I'm trying to create a windows form whose body will contain the content of a JSON string in the following format: Name of the object (Label) name of the attribute of the object - (TextBox) editable value (Label) name of the attribute of the object - (TextBox) editable value ... I have app
这是我在C#和JSON上的第一个小项目。 我被要求将JSON文件解析为以下内容:我试图创建一个窗体窗体,其主体将以下列格式包含JSON字符串的内容: Name of the object (Label) name of the attribute of the object - (TextBox) editable value (Label) name of the attribute of the object - (TextBox) editable value ... 我在json文件和8个对象中有大约35个属性。 总共有大约50种不同的属性。 我搜索了JSON - C# - JS
I am trying to convert a json string to a JObject using JObject.Parse, but running into the error "Error parsing positive infinity value. Path 'Modified.Date', line 1, position 52." Here is the part of json that is throwing the error on - { ..., "Modified" : { "Date" : ISODate("2013-02-21T22:23:57.118Z"), "User" : "Admin" },
我尝试使用JObject.Parse将json字符串转换为JObject,但遇到了错误“正确无穷值的错误解析。路径'Modified.Date',第1行,位置52。 这是抛出错误的JSON的一部分 - {...,“Modified”:{“Date”:ISODate(“2013-02-21T22:23:57.118Z”),“User”:“Admin”},...} 这里是我用来做解析的代码 - var jobj = JObject.Parse(formJson) 更新: json是通过使用mongodb的.ToJson()扩展方法生成的,通过在以下jsonwrite
What's the best practice for retrieving JSON values that may not even exist in C# using Json.NET? Right now I'm dealing with a JSON provider that returns JSON that sometimes contains certain key/value pairs, and sometimes does not. I've been using (perhaps incorrectly) this method to get my values (example for getting a double): if(null != jToken["width"]) width = double.Parse
使用Json.NET检索C#中可能不存在的JSON值的最佳做法是什么? 现在我正在处理返回JSON的JSON提供程序,该JSON有时包含某些键/值对,有时不包含。 我一直在使用(也许不正确)这个方法来获取我的值(例如获得一个double): if(null != jToken["width"]) width = double.Parse(jToken["width"].ToString()); else width = 100; 现在工作正常,但是当它们中有很多时,这很麻烦。 我最终写了一个扩展方法,只有在写完
I have some data in a C# DataSet object. I can serialize it right now using a Json.net converter like this DataSet data = new DataSet(); // do some work here to populate 'data' string output = JsonConvert.SerializeObject(data); However, this uses the property names from data when printing to the .json file. I would like to change the property names to be something different (say, change '
我在C#DataSet对象中有一些数据。 我可以使用像这样的Json.net转换器来序列化它 DataSet data = new DataSet(); // do some work here to populate 'data' string output = JsonConvert.SerializeObject(data); 但是,这会在打印到.json文件时使用data的属性名称。 我想改变属性名称是不同的(比如,将'foo'改为'bar')。 在Json.net文档中,在“序列化和反序列化JSON”→“序列化属性”下,它表示“JsonProper
I have the following code: var user = (Dictionary<string, object>)serializer.DeserializeObject(responsecontent); The input in responsecontent is JSON, but it is not properly parsed into an object. How should I properly deserialize it? I am assuming you are not using Json.NET (Newtonsoft.Json NuGet package). If this the case, then you should try it. It has the following features: L
我有以下代码: var user = (Dictionary<string, object>)serializer.DeserializeObject(responsecontent); responsecontent内容中的输入是JSON,但未正确解析为对象。 我应该如何正确地反序列化它? 我假设你没有使用Json.NET(Newtonsoft.Json NuGet包)。 如果是这种情况,那么你应该尝试一下。 它具有以下特点: LINQ to JSON JsonSerializer用于快速将.NET对象转换为JSON并返回 Json.NET可以选择性地生
I am using Json.NET to serialize a class to JSON. I have the class like this: class Test1 { [JsonProperty("id")] public string ID { get; set; } [JsonProperty("label")] public string Label { get; set; } [JsonProperty("url")] public string URL { get; set; } [JsonProperty("item")] public List<Test2> Test2List { get; set; } } I want to add a JsonIgnore() attr
我正在使用Json.NET将一个类序列化为JSON。 我有这样的班级: class Test1 { [JsonProperty("id")] public string ID { get; set; } [JsonProperty("label")] public string Label { get; set; } [JsonProperty("url")] public string URL { get; set; } [JsonProperty("item")] public List<Test2> Test2List { get; set; } } 我只想在Test2List为null时,将JsonIgnore()属性添加到T
Is it possible to return a dynamic object from a json deserialization using json.net? I would like to do something like this: dynamic jsonResponse = JsonConvert.Deserialize(json); Console.WriteLine(jsonResponse.message); latest json.net version allow do this: dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}"); Console.WriteLine(d.number); Console.WriteLine(d.str);
是否有可能使用json.net从json反序列化中返回动态对象? 我想要做这样的事情: dynamic jsonResponse = JsonConvert.Deserialize(json); Console.WriteLine(jsonResponse.message); 最新的json.net版本允许这样做: dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}"); Console.WriteLine(d.number); Console.WriteLine(d.str); Console.WriteLine(d.array.Count); 输出: 1000 string 6