草庐IT

json-dictionary

全部标签

c# - 如何将查询字符串转换为 json 字符串?

如何使用服务器端C#将查询字符串转换为键和值的JSON字符串?比如我要转换"ID=951357852456&FNAME=Jaime&LNAME=Lopez"到{"ID":"951357852456","FNAME":"Jaime","LNAME":"Lopez"}我知道如何手动解析和格式化,但在开始这条路之前,我想我会问一下,因为可能有一个库可以做得更好。谢谢! 最佳答案 这给出了你想要的完全相同的jsonvardict=HttpUtility.ParseQueryString("ID=951357852456&FNAME=Jaim

c# - 如何将 json 添加到 RestSharp POST 请求

我将以下JSON字符串作为字符串参数传递到我的C#代码中-AddLocation(stringlocationJSON):{"accountId":"57abb4d6aad4","address":{"city":"TEST","country":"TEST","postalCode":"TEST","state":"TEST","street":"TEST"},"alternateEmails":[{"email":"TEST"}],"alternatePhoneNumbers":[{"phoneNumber":"TEST"}],"alternateWebsites":[{"webs

c# - c# 和 newtonsoft 中的 JSON 日期和日期时间序列化

我们将JSON发送到由swagger定义的API,其中一些属性是格式为yyyy-MM-ddThh:mm:ss.000Z的DateTime(毫秒必须是3位数字,否则在端点验证失败)还有一些是日期(无时间)属性。我看到很多消息说使用这样的格式化程序:varjsonSettings=newJsonSerializerSettings();jsonSettings.DateFormatString="yyyy-MM-ddThh:mm:ss.000Z";//try.fffZtoovarjsonObject=Newtonsoft.Json.JsonConvert.DeserializeObject

c# - 如何将属性标记为 json 不可序列化?

正如标题所说,我想通过JavascriptSerializer将一个属性标记为不可序列化。怎样才能做到这一点?提前致谢。 最佳答案 我认为您只想应用ScriptIgnoreAttribute:[ScriptIgnore]publicstringIgnoreThis{get;set;} 关于c#-如何将属性标记为json不可序列化?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5

c# - 为什么 Dictionary[index] 会抛出 KeyNotFoundException 但 Hashtable[index] 不会?

知道为什么这种行为不同吗? 最佳答案 这是answer.TheprimaryreasonDictionarythrowsisthatthereisno"error"valuethatworksoveranyV.Hashtableisabletoreturnnullbecausethekeyisalwaysareferencetype. 关于c#-为什么Dictionary[index]会抛出KeyNotFoundException但Hashtable[index]不会?,我们在Stack

c# - 如何使用 JSON.NET 序列化静态或 const 成员变量?

我无法在任何地方找到这个问题的答案,但是当我尝试使用静态或常量成员变量序列化结构或类时,默认情况下它们不会序列化。如果我尝试通过设置MemberSerialization.OptIn强制序列化,我会收到错误。例如[JsonObject(MemberSerialization.OptIn)]publicclassTest{[JsonProperty]publicintx=1;[JsonProperty]publicstaticinty=2;}如果我尝试使用以下方法序列化此类:Testt=newTest();strings=JsonConvert.SerializeObject(t);我收

c# - 在输入 json 中将值 {null} 转换为类型 'System.DateTime' 时出错

当我尝试在我的Json中输入以下DateTime参数时抛出此JsonSerializationException:"Errorconvertingvalue{null}totype'System.DateTime'ininputjson"我在这里给出了输入:stringinputJSONString="{....,\"StartDateFrom\":null,\"StartDateTo\":null,\"EndDateFrom\":null,\"EndDateTo\":null,\....}";反序列化使用:scT=(SearchCriteriaTask)JsonConvert.Des

c# - Dictionary<TKey, TValue> 是否比 List<T> 上的 LINQ 更快?

我一般用List用于收藏。但是如果我需要快速查找一个集合,那么例如在下面的示例中,我将使用字典,以便我可以通过id快速查找它:Dictionary但是因为我可以使用LINQ来查询List无论如何,如下所示,是否有任何理由去解决使用字典而不是列表的麻烦?是字典更快还是LINQ在幕后做了一些使其同样快的事情?usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]

c# - 从 C# .NET 中的 DataTable 到 JSON

我是C#和.NET的新手,但我编写了这段代码来调用存储过程,然后我想获取返回的DataTable并将其转换为JSON。SqlConnectioncon=newSqlConnection("connectionstringhere");SqlDataAdapterda=newSqlDataAdapter();SqlCommandcmd=newSqlCommand("getDates",con);SqlParameterpar=newSqlParameter("@PlaceID",SqlDbType.Int);par.Value=42;da.SelectCommand=cmd;cmd.Pa

c# - 如何将 XML/JSON 文件转换为 C# 类?

我有这样的XML文件:XMLDeveloper'sGuide44.95Anin-depthlookatcreatingapplicationswithXML.MarkColsbergDolorsitamet5.95Loremipsum如何快速将其转换为C#类以通过LINQ使用访问数据?我是否必须为任何XML文件案例手动编写类?JSON格式怎么样?XSD是唯一的解决方案吗? 最佳答案 你有两种可能。方法一、XSD工具假设您的XML文件位于此位置C:\path\to\xml\file.xml打开开发者命令提示符您可以在StartMenu