小编Nis*_*San的帖子

在json.net中重命名JProperty

我有以下财产

{
  "bad": 
  {
    "Login": "someLogin",
    "Street": "someStreet",
    "House": "1",
    "Flat": "0",
    "LastIndication": 
    [
      "230",
      "236"
    ],
    "CurrentIndication": 
    [
      "263",
      "273"
    ],
    "Photo": 
    [
      null,
      null
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

以及如何将其从“坏”重命名为“好”。是的,我看到了Abi Bellamkonda的扩展方法

public static class NewtonsoftExtensions
{
    public static void Rename(this JToken token, string newName)
    {
        var parent = token.Parent;
        if (parent == null)
            throw new InvalidOperationException("The parent is missing.");
        var newToken = new JProperty(newName, token);
        parent.Replace(newToken);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是它得到了这个证明

无法将Newtonsoft.Json.Linq.JProperty添加到Newtonsoft.Json.Linq.JProperty。

.net c# json.net

3
推荐指数
1
解决办法
1390
查看次数

标签 统计

.net ×1

c# ×1

json.net ×1