2017-11-24 16 views
1

これは私がtimeOffTypeWithoutAllowance = trueを持つ最初のstaffTimeOffAllowancesエントリのallowancesUsedフィールドの値を抽出しようとしています私のデータ"無効な式、現在のトークン...正しく終了していません"というエラーを修正する方法はありますか?

{ 
    "errorCode": null, 
    "errorMessage": null, 
    "responseItems": [ 
    { 
     "personFirstName": "t16239d", 
     "personLastName": "submitter 1", 
     "hireDate": "20161106", 
     "terminationDate": null, 
     "startMonthYear": "01_2017", 
     "endMonthYear": "12_2017", 
     "staffTimeOffAllowances": [ 
     { 
      "officeCode": null, 
      "startMonthYear": null, 
      "endMonthYear": null, 
      "personId": null, 
      "personCode": null, 
      "allowancesIntotal": 10, 
      "allowancesUsed": 0, 
      "allowancesSubmitted": 0, 
      "allowancesApproved": 0, 
      "allowancesRemaining": 10, 
      "timeOffType": { 
      "id": 1284, 
      "continent": "EU", 
      "alphaId": "CA", 
      "code": "SUM1", 
      "description": "summer friday1", 
      "account": "ADMIN1", 
      "colourCode": "#CCCCCC", 
      "visibility": "R", 
      "approvalRequired": true, 
      "commentRequired": false, 
      "paid": true 
      }, 
      "timeOffTypeWithoutAllowance": false, 
      "proRataAllowanceData": false 
     }, 
     { 
      "officeCode": null, 
      "startMonthYear": null, 
      "endMonthYear": null, 
      "personId": null, 
      "personCode": null, 
      "allowancesIntotal": 0, 
      "allowancesUsed": 3, 
      "allowancesSubmitted": 0, 
      "allowancesApproved": 0, 
      "allowancesRemaining": 3, 
      "timeOffType": { 
      "id": 1342, 
      "continent": "EU", 
      "alphaId": "CA", 
      "code": "SICK", 
      "description": "Sickness", 
      "account": "SICK", 
      "colourCode": "#CCCCCC", 
      "visibility": "R", 
      "approvalRequired": true, 
      "commentRequired": false, 
      "paid": true 
      }, 
      "timeOffTypeWithoutAllowance": true, 
      "proRataAllowanceData": false 
     } 
     ] 
    } 
    ] 
} 

です。

ムー現在の試行は、次のとおりです。

staffTimeOffAllowances[?(@.timeOffTypeWithoutAllowance==true)].allowancesUsed[0] 

それは罰金コンパイルが、その後、私はそれをプレビューしようとすると、それは現在のトークンstaffTimeOffAlowancesは、[(@正常に終了していない、

無効な式で失敗?

私は同じ表現のバリエーションをたくさん試しましたが、喜びはありませんでした。誰かが私に行方不明を教えてください。

答えて

2

json基本語は絶対式が必要です。私はフィールドの式として使用することができます( "リーフ"値を使用する特別なフィールド式 - "."が必要と予測できない結果を生成する可能性があります)ように、あなたのクエリをあなたの希望のJSONプロパティの1つ上のレベルを停止することをお勧めします。このクエリとフィールドのマッピングで問題ないはず、と述べた:

<queryString language="json"> 
    <![CDATA[responseItems.staffTimeOffAllowances(timeOffTypeWithoutAllowance == true)[0]]]> 
</queryString> 
<field name="allowancesUsed" class="java.lang.Integer"/> 

はJasperReportsのを起動すると、あなたは、高度な/より柔軟jsonql言語を使用することができます6.3.1。

  • この1:ただ、どちらかと上記のqueryString宣言を置き換える「、どこからでもstaffTimeOffAllowancesプロパティを取得timeOffTypeWithoutAllowanceを持ってその子を取得し、最初のいずれかを選択します。

    <queryString language="jsonql"> 
        <![CDATA[..staffTimeOffAllowances.*(timeOffTypeWithoutAllowance == true)[0]]]> 
    </queryString> 
    

    このクエリは、に変換します「

  • か、この1:

    <queryString language="jsonql"> 
        <![CDATA[..timeOffTypeWithoutAllowance(@val == true)^[0]]]> 
    </queryString> 
    

    このクエリは、に変換:「どこからでも値でtimeOffTypeWithoutAllowanceプロパティを取得その親を取得し、最初のいずれかを選択し、」

重要な注意jsonjsonqlは無関係なカスタムクエリ言語ですいくつかの類似点にもかかわらず、JsonPathに。 jsonは、JSON構造をクエリする方法を提供する最初の(非常に単純な)試みであり、jsonqlの後にjsonを置き換えることを意味し、より多くの機能を提供し、より予測可能です。

+0

ありがとうございます!私はjsonqlを知らないと告白する必要があります。テンプレートはJSONに設定されていましたが、このフィールドは必要なフラグです。私は言語(と私のデータソースクラス)をjsonqlに変更してしまいました。これらのヒントは非常に貴重なものになるでしょう - もう一度感謝します。 – user2668539

関連する問題