如何在C#中更改Android(JsonProperty [" value"])值?

时间:2016-04-28 05:53:42

标签: c# android json

public class RootObject
{

[JsonProperty("585709" )]
public List<SummonerId> SummonerId { get; set; }

}

我有一个类使用JsonProperty [&#34; 585709&#34;]进行我的JSON Api调用。 这正是我想要的但是......我面临的问题是,该属性必须根据用户的身份证号码进行更改。

我尝试过的事情:

这似乎有效但是当Json调用时,值会搜索原始值&#34; 585709&#34;。

       public class CustomDataContractResolver : DefaultContractResolver
        {
        public static readonly CustomDataContractResolver Instance = new CustomDataContractResolver();

        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var property = base.CreateProperty(member, memberSerialization);
            if (property.DeclaringType == typeof(RootObject))
            {
                if (property.PropertyName.Equals("585709", StringComparison.OrdinalIgnoreCase))
                {
                    property.PropertyName = "569099";
                }
            }
            return property;
        }
     }


  var prop = JsonConvert.SerializeObject(r, new JsonSerializerSettings {     ContractResolver = CustomDataContractResolver.Instance });
        var root = JsonConvert.DeserializeObject<RootObject>(request)

有没有办法可以为类改变JsonProperty的值?

0 个答案:

没有答案