草庐IT

JSON_ENCODE

全部标签

c# - 在 JSON 中获得 400 webservice 状态时返回 false

在我的代码隐藏文件中,我调用了这个函数:privatevoidloginAction(objectsender,TappedRoutedEventArgse){Webservicewebservice=newWebservice();webservice.getUser(txtLogin.Text,txtPass.Text);}然后在网络服务中我这样做:publicvoidgetUser(Stringuser,Stringpassword){StringstrUrl=String.Format("http://*******/nl/webservice/abc123/members/l

c# - JSON.NET DataContractJsonSerializer 和 Newtonsoft JSON 序列化程序有什么区别

谁能帮帮我。内置的JSON.NETDataContractJsonSerializer和NewtonsoftJSON序列化器有什么区别?我可以将一个或另一个与WebAPI一起使用是否正确,我为什么要选择一个? 最佳答案 你可以在这里找到性能比较(来源:newtonking.com)这是功能比较,http://james.newtonking.com/projects/json/help/index.html?topic=html/JsonNetVsDotNetSerializers.htm

c# - Json.NET Serialization Callbacks 中的 StreamingContext 参数有什么用?

我试图了解Json.NET序列化回调中应该包含的StreamingContext参数是什么,首先我以为你会允许我访问正在读取的当前json树,但它似乎并没有,我尝试了JSON对象的可能排列,但没有一个我可以从StreamingContext参数中得到任何东西。这是一个例子,展示了我正在做的事情,如果我错了请纠正我:usingSystem;usingSystem.Runtime.Serialization;usingNewtonsoft.Json;namespaceTestes{publicclassProgram{[JsonObject(MemberSerialization.OptI

c# - JSON .Net 在反序列化时不遵守 PreserveReferencesHandling

我有一个双向链表,我正在尝试反序列化。我的场景与这个SO密切相关:DoublyLinkedListtoJSON我有以下JSON设置:_jsonSettings=newJsonSerializerSettings(){TypeNameHandling=TypeNameHandling.Auto,ConstructorHandling=ConstructorHandling.AllowNonPublicDefaultConstructor,PreserveReferencesHandling=PreserveReferencesHandling.Objects,ObjectCreation

c# - Json.NET如何在反序列化过程中进行依赖注入(inject)?

当我有一个没有默认构造函数的类时,即使用依赖注入(inject)来传递其依赖项时,Newtonsoft.Json可以创建这样的对象吗?例如:publicclassSomeFoo{privatereadonlyIFooDependency_dependency;publicSomeFoo(IFooDependencydependency){if(dependency==null)thrownewArgumentNullException("dependency");_dependency=dependency;}publicstringData{get;set;}publicintMor

c# - 如何告诉 Json.NET 忽略第 3 方对象中的属性?

Json.NET文档说您使用JsonIgnore来不序列化类中的某些属性:publicclassAccount{publicstringFullName{get;set;}publicstringEmailAddress{get;set;}[JsonIgnore]publicstringPasswordHash{get;set;}}在使用JsonConvert.SerializeObject序列化第3方对象时,如何让Json.NET忽略特定属性? 最佳答案 制作自定义合约解析器:publicclassShouldSerializeC

c# - 当我事先不知道 key 时,如何在 C# 中解析 JSON 对象?

我有一些JSON数据,如下所示:{"910719":{"id":910719,"type":"asdf","ref_id":7568},"910721":{"id":910721,"type":"asdf","ref_id":7568},"910723":{"id":910723,"type":"asdf","ref_id":7568}}我如何使用JSON.net解析它?我可以先这样做:JObjectjFoo=JObject.Parse(data);我需要能够遍历此列表中的每个对象。我希望能够做这样的事情:foreach(stringref_idin(string)jFoo["ref_

c# - 使用带有 ItemRequired = Required.Always 的 Json.Net 反序列化时忽略属性

我正在使用Json.Net将类序列化和反序列化为json并返回。我添加到标有[JsonObject(ItemRequired=Required.Always)]的类中(或Required.Always)一个新的只读属性。这导致以下JsonSerializationException:Newtonsoft.Json.JsonSerializationException:Requiredproperty''notfoundinJSON我想用JsonIgnore标记该属性会解决问题,但这不起作用。我如何告诉Json.Net这个属性应该被忽略?这是重现该问题的最小示例:[JsonObject(

c# - 将 List<KeyValuePair<string, string>> 序列化为 JSON

我是JSON的新手,请帮忙!我正在尝试序列化List>作为JSON目前:[{"Key":"MyKey1","Value":"MyValue1"},{"Key":"MyKey2","Value":"MyValue2"}]预期:[{"MyKey1":"MyValue1"},{"MyKey2":"MyValue2"}]我引用了this中的一些示例和this.这是我的KeyValuePairJsonConverter:JsonConverterpublicclassKeyValuePairJsonConverter:JsonConverter{publicoverridevoidWriteJs

c# - 如何使用 json.net 将枚举序列化为不同的属性名称

我有以下枚举publicenumPermissionType{[JsonProperty(PropertyName="can_fly")]PermissionToFly,[JsonProperty(PropertyName="can_swim")]PermissionToSwim};和一个具有这个属性的类[JsonProperty(PropertyName="permissions",ItemConverterType=typeof(StringEnumConverter))]publicIListPermissionKeynames{get;set;}`我想将枚举列表序列化为字符串列