草庐IT

system.json

全部标签

c# - 使用动态属性名称将数据序列化为 json 字符串

我有一个接受键和值的方法。两个变量都可以有动态内容。key=>是一个动态字符串,可以是任何东西,例如“上次发送日期”value=>是一个对象,它可以是任何东西,例如"2014-10-10"由于键是动态值,例如“LastSentDate”或传递给方法的任何键,因此我希望json属性是键字符串的值,而不是字面上的键本身...publicvoidSetRowVariable(stringkey,objectvalue){varobj=new{key=value};//keypropertyisliterallytakenmaybeanonymobjectisnotagoodidea?stri

c# - 为什么 System.Array 类实现 IList 但不提供 Add()

这段代码:int[]myArr={1,2};myArr.Add(3);在构建时抛出以下错误:errorCS1061:'System.Array'doesnotcontainadefinitionfor'Add'andnoextensionmethod'Add'acceptingafirstargumentoftype'System.Array'couldbefound(areyoumissingausingdirectiveoranassemblyreference?)IList接口(interface)有Add()方法,为什么Array没有实现?更新:我从答案中看到它确实明确地实现了

c# - Newtonsoft JSON - 反序列化JSON时如何使用JsonConverter.ReadJson方法进行类型转换

我需要帮助了解如何使用JsonConverter.ReadJson方法将任意数量的类型(字符串、bool值、日期、整数、数组、对象)的值转换为特定的自定义类型。例如我有以下;publicoverrideobjectReadJson(JsonReaderreader,TypeobjectType,objectexistingValue,JsonSerializerserializer){//wherereader.Valuecouldbeastring,boolean,Date,int,array,object//andinthisexamplethevalueofreader.Valu

c# - System.Windows.Input 不存在?

我的程序顶部有usingSystem.Windows.Input;,但它给我一个错误提示:Thetypeornamespacename'Input'doesnotexistinthenamespace'System.Windows'(areyoumissinganassemblyreference?)当我在Windows之后的句点上让IntelliSense弹出时,它只将Forms列为有效选项。我在VisualC#2010Express中使用.NETFramework4.0...我该如何解决这个问题? 最佳答案 我怀疑您创建的是Wi

c# - 未知模块中发生类型为 'System.IO.FileNotFoundException' 的未处理异常

我正在开发一个C#应用程序,但在调试运行时出现以下错误:Anunhandledexceptionoftype'System.IO.FileNotFoundException'occurredinUnknownModule.Additionalinformation:Couldnotloadfileorassembly'Autodesk.Navisworks.Timeliner.dll'oroneofitsdependencies.Thespecifiedmodulecouldnotbefound.Autodesk.Navisworks.Timeliner.dll位于应用程序的调试文件夹

c# - 抛出 'System.StackOverflowException' 类型的异常

我的程序抛出这个异常:System.StackOverflowException当编译器执行设置属性时。wine类:classwine{publicintyear;publicstringname;publicstaticintno=5;publicwine(intx,stringy){year=x;name=y;no++;}publicintprice{get{returnno*5;}set{price=value;}}}程序类:classProgram{staticvoidMain(string[]args){winew1=newwine(1820,"JackDaniels");C

c# 到 json 无法在 View 中正确呈现

您好,我正在尝试将字符串发送到看起来像json的View。我正在发送地点列表:classPlace{publicstringtitle{get;set;}publicstringdescription{get;set;}publicdoublelatitude{get;set;}publicdoublelongitude{get;set;}}ListplaceList=newList();//addplacestoPlaceList//ThenidothisSystem.Web.Script.Serialization.JavaScriptSerializeroSerializer=n

c# - 如何在我的 JSON 模型类中使用保留关键字作为标识符?

我以前从未使用过WebAPI,但我需要一个可以接受/返回JSON对象的Web服务,使用它似乎是一件合理的事情。它看起来非常简单(如果不是为了我的目的有点矫枉过正),但我需要处理的数据结构看起来像:{"values":["foo","bar"],"default":"bar"}所以我去制作一个模型对象:classDropDownValues{publicstring[]values{get;set;}publicstringdefault{get;set;}}问题是default似乎是一个protected关键字。一定有办法解决这个问题,对吧? 最佳答案

c# - 等于 System.Collections.Generic.List<T>... 的方法?

我正在创建一个派生自List的类...publicclassMyList:List{}我已经覆盖了MyListItem的Equals...publicoverrideboolEquals(objectobj){MyListItemli=objasMyListItem;return(ID==li.ID);//IDisapropertyofMyListItem}我也想在MyList对象中有一个Equals方法,它将比较列表中的每个项目,在每个MyListItem对象上调用Equals()。简单地调用...会很好MyListl1=newMyList(){newMyListItem(1),ne

c# - 在 System.IO.Directory.GetFiles() 中排除文件扩展名

有没有办法获取文件夹中的文件数,但我想排除扩展名为jpg的文件?Directory.GetFiles("c:\\Temp\\").Count(); 最佳答案 试试这个:varcount=System.IO.Directory.GetFiles(@"c:\\Temp\\").Count(p=>Path.GetExtension(p)!=".jpg");祝你好运! 关于c#-在System.IO.Directory.GetFiles()中排除文件扩展名,我们在StackOverflow上找到