Newtonsoft JSON 反序列化在使用 ConfuserEx 时不起作用

gav*_*ave 3 c# json json.net confuserex

我有一个这样的 JSON 类:

public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

但是当我使用 ConfuserEx 混淆我的程序集时,UpdatesAvailableLinkOfNewVersion的值为空:/

我已经尝试了以下所有方法:

[Obfuscation(Exclude = false, Feature = "-rename")]我的 JSON 类上方添加属性:

[Obfuscation(Exclude = false, Feature = "-rename")]
public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

[Serializable]我的 JSON 类上方添加属性:

[Serializable]
public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在我的 JSON 类上方添加两个属性:

[Serializable]
[Obfuscation(Exclude = false, Feature = "-rename")]
public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

但是我尝试的所有方法都失败了:/

我的混淆属性:

  <rule pattern="true" preset="maximum" inherit="false">
    <protection id="anti ildasm" />
    <protection id="anti tamper" />
    <protection id="constants" />
    <protection id="ctrl flow" />
    <protection id="anti dump" />
    <protection id="anti debug" />
    <protection id="invalid metadata" />
    <protection id="ref proxy" />
    <protection id="resources" />
    <protection id="typescramble" />
    <protection id="rename" />
  </rule>
Run Code Online (Sandbox Code Playgroud)

当我从我的 ConfuserEx 配置文件中删除“重命名”保护时,我的程序集会像这样崩溃: 在此处输入图片说明

任何帮助,将不胜感激。

谢谢!

Pet*_*r B 5

尝试使用JsonProperty属性将字段名称设置为其固定值:

public class UpdateCheck
{
    [JsonProperty("UpdatesAvailable")]
    public bool UpdatesAvailable { get; set; }

    [JsonProperty("LinkOfNewVersion")]
    public string LinkOfNewVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)