jjzjj

deserialization

全部标签

c# - 使用 JSON.NET 解析嵌套的 JSON 对象

我的JSON提要有这样的嵌套对象:{"id":1765116,"name":"StrozeR","birth":"2009-08-12","avatar":"http:\/\/static.erepublik.com\/uploads\/avatars\/Citizens\/2009\/08\/12\/f19db99e9baddad73981d214a6e576ef_100x100.jpg","online":true,"alive":true,"ban":null,"level":61,"experience":183920,"strength":25779.42,"rank":{"

c# - Newtonsoft Json 将值 {null} 转换为类型 'System.Int32' 时出错

执行AJAX请求时出现以下错误:Errorconvertingvalue{null}totype'System.Int32'.Path'[5].tabID',line1,position331.错误出现在我的processRequest(...)的第二行publicvoidProcessRequest(HttpContextcontext){stringstrJson=newStreamReader(context.Request.InputStream).ReadToEnd();Listelements=JsonConvert.DeserializeObject>(strJson);

c# - 在 MVC 中将 JSON 字符串转换为 JsonResult

我们正在尝试制作模拟服务来为JSON提供服务。我们将纯JSON字符串存储在静态文件中,并希望将它们按原样提供给客户端,而不需要任何额外的包装器。例如。我们有json字符串{"result_code":200,{"name":"John","lastName":"Doe"}}并且我们想像这样在客户端上获得json响应而不需要任何内容或数据包装器。我们有使用数据契约并将json反序列化为C#对象的解决方案,但这有点复杂,我们不需要它。谢谢 最佳答案 您可以通过引用System.Web.Mvc来完成此操作。我放在一起的快速控制台应用程序中

c# - 使用自动修剪字符串反序列化 json

我使用Newtonsoft.Json库有没有办法在反序列化期间从任何字符串数据中修剪空格?classProgram{classPerson{[JsonProperty("name")]publicstringName;}staticvoidMain(string[]args){varp=JsonConvert.DeserializeObject(@"{name:""John""}");Console.WriteLine("Nameis:\"{0}\"",p.Name);}}添加:最后,我得到了自定义转换器的解决方案。不好,但比使用Trim()的属性更好。如果有人有任何想法如何以更自然的

c# - 反序列化后初始化私有(private)只读字段

我需要在反序列化后初始化私有(private)只读字段。我有以下数据契约(Contract):[DataContract]publicclassItem{publicItem(){//ConstructornotcalledatDeserialization//becauseofFormatterServices.GetUninitializedObjectisused//sofieldwillnotbeinitializedbyconstructoratDeserialization_privateReadonlyField=newobject();}//Initialization

c# - 如何使用 json.net 将 json 数组添加到 JObject 的属性中

我很难弄清楚如何将一组json对象添加到现有的JObject。假设我有一个只有“Modified”属性的JObject,我想添加另一个包含json对象数组的属性“IntersectGroups”,我该怎么做?我有一个JObject[],当我序列化它时它完全符合我需要的格式,但我正在寻找这样的东西:mainJObject.Add("IntersectGroups",myJObjectArray)这是我序列化时想要的最终json的示例。..."Modified":"2012-11-26T10:21:04.693","IntersectGroups":[{"Id":1004,"UserId"

c# - 将嵌套的 XML 元素反序列化为 C# 中的类

我有以下我无法控制的XML结构(为简洁起见进行了编辑)。Blue3Hatchback我有以下类(class):[XmlRoot("GetVehicles"),XmlType("Vehicle")]publicclassVehicle{publicstringColour{get;set;}publicstringNumOfDoors{get;set;}publicstringBodyStyle{get;set;}}我希望能够将XML反序列化为该Vehicle类的单个实例。99%的情况下,XML应该只返回一个“Vehicle”元素。如果它在'Vehicles'元素中包含多个'Vehicl

c# - XML 文档 (1,2) 中存在错误,System.InvalidOperationException : <AuthorizationResult xlms :""> was not expected

从API发送的XML0StringAccessTokenStringAccessTokenPolarisSampleUser72013-05-27T16:57:46.323响应类usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Xml;usingSystem.Xml.Schema;usingSystem.Xml.Serialization;namespacePAPIAutomatedTestingToo

c# - 如何在 C# 中反序列化包含多种类型元素的 XML 数组

我正在尝试反序列化以下文件:WayneStamkos2334SidneyLindros4144MartinRoy1512PaulForsberg2151RobertoRinne1823使用以下代码:namespaceConsoleApplication2{[XmlRoot("league")]publicclassLeague{[XmlArray("players")][XmlArrayItem("skater")]publicListskaters{get;set;}[XmlArrayItem("goalie")]publicListgoalies{get;set;}}publicc

c# - 在枚举参数中使用短划线 (-) 字符

publicenumTimeFormat{@12-hour,@24-hour}你好,我使用newtonsoft反序列化器将json字符串反序列化为对象。JsonDeserializer检查枚举参数名称。如果它与json字符串相同。它将字符串转换为枚举。我可以在枚举中使用破折号、减号(-)字符作为枚举参数吗?我试着像上面那样使用,但我无法编译项目。然后我尝试了这个。[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]publicenumTimeFormat{[JsonProperty("12-hou