我想获取必须数组上的元素。我有这样的查询
{
"from": 0,
"query": {
"bool": {
"must": [
{
"query_string": {
"analyze_wildcard": true,
"default_operator": "and",
"fields": [
"entityStatusDesc"
],
"query": "$entityStatusDesc"
}
},
{
"query_string": {
"analyze_wildcard": true,
"default_operator": "and",
"fields": [
"instanceStartTime"
],
"query": "$instanceStartTime"
}
},
{
"match": {
"model": {
"query": "instance"
}
}
}
]
}
},
"size": 10,
}
我试过了;
JObject o = JObject.Parse(json);
var acme = o.SelectToken("$.must[0]");
但是没用。我想通过 Must[0] 调用获取 json 的这一部分;
{
"query_string": {
"analyze_wildcard": true,
"default_operator": "and",
"fields": [
"entityStatusDesc"
],
"query": "$entityStatusDesc"
}
},
是否有任何不同的方式来获取必须区域?如果有人可以帮助我,我将不胜感激。谢谢。
最佳答案
选项之一是提供完整路径:
var acme = o.SelectToken("$.query.bool.must[0]");
或者只使用索引器:
var acme = o["query"]["bool"]["must"][0];
关于c# - 查询Json如何获取must数组内的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64714635/