我试图从下面的 json 中检索日期和相应的计数,结果证明我做不到。经过一番努力,我以下面带有嵌套链表的奇怪代码结束。我如何选择 solr_date 并算作出现在最后:(我欢迎任何可以做到这一点的图书馆)
{
"responseHeader":{
"status":0,
"QTime":2,
"params":{
"facet":"true",
"fl":" ",
"indent":"true",
"facet.query":" solr_date",
"q":"solr_body:party",
"facet.field":"solr_date",
"json.nl":"arrarr",
"wt":"json",
"fq":" "}},
"response":{"numFound":19,"start":0,"docs":[
{},
{},
{},
{},
{},
{},
{},
{},
{},
{}]
},
"facet_counts":{
"facet_queries":{
" solr_date":0},
"facet_fields":{
"solr_date":
[
["2013-06-19T13:48:02Z",10], *********************************
["2013-07-25T13:48:02Z",2],
["2013-07-27T13:48:02Z",2],
["2013-07-24T13:48:02Z",1], I need these numbers individually. Date and corresponding number.
["2013-07-26T13:48:02Z",1],
["2013-07-28T13:48:02Z",1],
["2013-07-29T13:48:02Z",1],
["2013-07-30T13:48:02Z",1]]}, ***************************
"facet_dates":{},
"facet_ranges":{}}}
Java代码如下:
ObjectMapper mapper = new ObjectMapper();
// JsonNode rootNode = m.readTree(new URL("http://173.255.245.138:8983/solr/collection1/select?q=*%3A*&wt=json&indent=true"));
Map<String, Object> mapObject = mapper.readValue(new URL("http://ipa.ddr.ess.000:8983/solr/collection1/select?q=solr_body%3Aparty&fq=+++&fl=+&wt=json&json.nl=arrarr&indent=true&facet=true&facet.query=+solr_date&facet.field=solr_date"),new TypeReference<Map<String, Object>>() {});
LinkedHashMap<String,LinkedHashMap<String,LinkedHashMap<String,ArrayList<String>>>> list = (LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, ArrayList<String>>>>) mapObject.get("facet_counts");