首页 > 解决方案 > 如何在newtonsoft 中得到没有jPath 属性的结果?

问题描述

我想在没有某些属性的情况下获得结果,有人知道如何在 json.net 上工作吗?Goessner 文章中的 jPath "hello word" 文档中有一个示例,

{ 
"store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}

如果我想过滤所有带有isbn编号的书籍,我可以使用jToken.SelectTokens("$..book[?(@.isbn)]"),但是,如果我想过滤所有没有isbn编号的书籍,我该如何过滤它们以及json.net是否有这个功能。

标签: c#json.netjsonpath

解决方案


编辑:

抱歉,这仅在密钥存在时有效null,如果不存在则无效。搞混了


目前,您可以使用$..book[?(@.isbn==null)].

这个工作的原因与我最近回答的另一个问题有关:https ://stackoverflow.com/a/69069335/878701


推荐阅读