这是我从ElasticSearch查询返回的json字符串:
var response =
{
"took":1,
"timed_out":false,
"_shards":
{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":
{
"total":278,
"max_score":0.0,
"hits":[]
},
"aggregations":
{
"nombindiam":
{
"doc_count_error_upper_bound":0,
"sum_other_doc_count":0,
"buckets":
[
{"key":15,"doc_count":12},
{"key":20,"doc_count":24},
{"key":25,"doc_count":44}
]
}
}
}
如何获取仅包含存储桶节点键属性值的整数列表,如下所示:
List<int> myKeyValues= new List<int>() { 15, 20, 25 };
这是我到目前为止得到的:
JObject json = JObject.Parse(response);
var myKeyValues = json["aggregations"]["nombindiam"]["buckets"].ToList();
你快到了,你只需要选择键...
var myKeyValues = json["aggregations"]["nombindiam"]["buckets"]
.Select(x => x["key"])
.ToList();