c# - 如何在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是否有这个功能。
解决方案
编辑:
抱歉,这仅在密钥存在时有效null
,如果不存在则无效。搞混了
目前,您可以使用$..book[?(@.isbn==null)]
.
这个工作的原因与我最近回答的另一个问题有关:https ://stackoverflow.com/a/69069335/878701
推荐阅读
- python - 如何将多个字符插入字符串中的随机不相邻位置
- node.js - Knex.js postgresql 数据库连接
- python - 用 d1 的 dictionary.keys() 更新 d2 的所有 dictionary.keys()
- apache-kafka - 卡夫卡准备探测失败
- opencl - 使用带变量的算术表达式时,OpenCL 变量赋值失败
- python-3.x - python 设置工具创建不需要的隐式命名空间包?
- django - Nginx 将来自与客户端相同服务器的 API 请求列入白名单,阻止所有其他请求
- angular - 如何投掷首先进入触发动画角度6
- video - 如何在具有 .hevc 扩展名的视频中添加声音而不更改其扩展名
- r - 使用 ggplot2 在 R 中删除不相关的级别