この投稿は非常に役に立ちました。この質問が尋ねられたのはかなりの時期ですが、私が同じ問題を抱えていたので、他の人にも役立つかもしれません. Google API for JSON - GSON を使用してこの問題を解決しました。
Solr が返す応答は JSON 形式ではありません。変換する必要があります。solr から応答を取得し、json オブジェクトに変換しました。
当初、私の回答は次のとおりでした。
{docs=[SolrDocument{id=1, uuid=7fe08f79-e184-454d-908f-08b32583a822, packName=Workflow Logger-Pack, packDescription=Workflow Logger-Pack, packAuthor=NetApp, packVersion=1.0.0, packDate=May 22, 2014, 3:10 pm, entityName=[Workflow Logger, Wait, Logging cmd, Test cmd for multiple Parameter Types], entityDescription=[Workflow Logger, Wait Command, Logging command, Test cmd for multiple Parameter Types], entityType=[Workflow, Command, Command, Command], _version_=1468794552324194304}, SolrDocument{id=2, uuid=7fe08f79-e184-454d-908f-08b32583a822, packName=Workflow Logger-Pack New, packDescription=Workflow Logger-Pack, packAuthor=NetApp, packVersion=2.0.0, packDate=May 22, 2014, 3:13 pm, entityName=[Workflow Logger, Wait, Logging cmd, Test cmd for multiple Parameter Types], entityDescription=[Workflow Logger, Wait Command, Logging command, Test cmd for multiple Parameter Types], entityType=[Workflow, Command, Command, Command], _version_=1468794760693022720}, SolrDocument{id=3, uuid=7fe08f79-e184-454d-908f-08b32583a822, packName=Workflow Logger-Packs updated, packDescription=Workflow Logger-Pack, packAuthor=NetApp, packVersion=3.0.0, packDate=May 22, 2014, 3:32 pm, entityName=[Workflow Logger, Wait, Logging cmd, Test cmd for multiple Parameter Types], entityDescription=[Workflow Logger, Wait Command, Logging command, Test cmd for multiple Parameter Types], entityType=[Workflow, Command, Command, Command], _version_=1468795898385399808}, SolrDocument{id=5, uuid=7fe08f79-e184-454d-908f-08b32583a822, packName=Workflow Logger-Pack New, packDescription=Workflow Logger-Pack, packAuthor=NetApp, packVersion=2.0.0, packDate=June 17, 2014, 7:02 am, entityName=[Workflow Logger, Wait, Logging cmd, Test cmd for multiple Parameter Types], entityDescription=[Workflow Logger, Wait Command, Logging command, Test cmd for multiple Parameter Types], entityType=[Workflow, Command, Command, Command], _version_=1471140110510587904}]}
私のコード:
HttpSolrServer server= new HttpSolrServer("http://localhost:8983/solr");
server.setParser(new XMLResponseParser());
Gson gson= new Gson();
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
solrQuery.setHighlight(true);
solrQuery.setHighlightRequireFieldMatch(true);
QueryResponse response= server.query(solrQuery);
SolrDocumentList docs = response.getResults();
String res= gson.toJson(docs);
System.out.println(res);
これで、次のように JSON に変換されます。
[
{
"id": "1",
"uuid": "7fe08f79-e184-454d-908f-08b32583a822",
"packName": "Workflow Logger-Pack",
"packDescription": "Workflow Logger-Pack",
"packAuthor": "NetApp",
"packVersion": "1.0.0",
"packDate": "May 22, 2014, 3:10 pm",
"entityName": [
"Workflow Logger",
"Wait",
"Logging cmd",
"Test cmd for multiple Parameter Types"
],
"entityDescription": [
"Workflow Logger",
"Wait Command",
"Logging command",
"Test cmd for multiple Parameter Types"
],
"entityType": [
"Workflow",
"Command",
"Command",
"Command"
],
"_version_": 1468794552324194300
},
{
"id": "2",
"uuid": "7fe08f79-e184-454d-908f-08b32583a822",
"packName": "Workflow Logger-Pack New",
"packDescription": "Workflow Logger-Pack",
"packAuthor": "NetApp",
"packVersion": "2.0.0",
"packDate": "May 22, 2014, 3:13 pm",
"entityName": [
"Workflow Logger",
"Wait",
"Logging cmd",
"Test cmd for multiple Parameter Types"
],
"entityDescription": [
"Workflow Logger",
"Wait Command",
"Logging command",
"Test cmd for multiple Parameter Types"
],
"entityType": [
"Workflow",
"Command",
"Command",
"Command"
],
"_version_": 1468794760693022700
},
{
"id": "3",
"uuid": "7fe08f79-e184-454d-908f-08b32583a822",
"packName": "Workflow Logger-Packs updated",
"packDescription": "Workflow Logger-Pack",
"packAuthor": "NetApp",
"packVersion": "3.0.0",
"packDate": "May 22, 2014, 3:32 pm",
"entityName": [
"Workflow Logger",
"Wait",
"Logging cmd",
"Test cmd for multiple Parameter Types"
],
"entityDescription": [
"Workflow Logger",
"Wait Command",
"Logging command",
"Test cmd for multiple Parameter Types"
],
"entityType": [
"Workflow",
"Command",
"Command",
"Command"
],
"_version_": 1468795898385399800
},
{
"id": "5",
"uuid": "7fe08f79-e184-454d-908f-08b32583a822",
"packName": "Workflow Logger-Pack New",
"packDescription": "Workflow Logger-Pack",
"packAuthor": "NetApp",
"packVersion": "2.0.0",
"packDate": "June 17, 2014, 7:02 am",
"entityName": [
"Workflow Logger",
"Wait",
"Logging cmd",
"Test cmd for multiple Parameter Types"
],
"entityDescription": [
"Workflow Logger",
"Wait Command",
"Logging command",
"Test cmd for multiple Parameter Types"
],
"entityType": [
"Workflow",
"Command",
"Command",
"Command"
],
"_version_": 1471140110510588000
}
]
それが役に立てば幸い。