0
{responseHeader={status=0,QTime=0,params={q=ketan,wt=[javabin,javabin],version=2.2}},response={numFound=1,start=0,docs=[SolrDocument[{user_first_name=Ketan, customerid=5,killname=Hockey, areaname=Paud, categoryname=Sports, last_name=Kore, statename=Maharashtra, cityname=Pune, contactno=124555698}]]}}

この応答 SOLR を受け取り、これから JSONObject SOlr Document を取得したいと考えています。この応答を解析する方法を教えてください。

4

3 に答える 3

0

あなたが言及した文字列はjson文字列です(jsonはJavascript Object Notationです)。デコードにはjava-jsonlibを使用してみてください。これが例です。

于 2012-05-29T13:06:37.580 に答える
0

この投稿は非常に役に立ちました。この質問が尋ねられたのはかなりの時期ですが、私が同じ問題を抱えていたので、他の人にも役立つかもしれません. 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
  }
]

それが役に立てば幸い。

于 2014-06-18T09:29:34.007 に答える
0

JSONObject を作成するには、ハッシュ マップを使用する必要があります。現在、solrj は出力として json 形式をサポートしていません。

于 2012-12-20T10:22:42.933 に答える