亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用方言“Mvel”檢查drools中的if語句值?

如何使用方言“Mvel”檢查drools中的if語句值?

冉冉說 2021-06-21 17:59:24
我下面有一個json"root":[  {    "refDataId": 1,    "children": [      {        "refDataId": 20      },      {        "refDataId": 99,        "otherValue": "Facility"      }    ]  },  {    "refDataId": 2,    "children": [      {        "refDataId": 30      },      {        "refDataId": 99,        "otherValue": "Officer"      }    ]  }]如何使用規則 drools 中的 if 語句檢查上面的值?我編輯了問題。這是為了流口水規則例如我的規則是:rule "test"    when        RuleEngine(inputObject!.adultHealth!.children contains 99)    then        info("children contains value 99");end以及如何檢查的價值"refDataId": 99,和"otherValue": "Officer"?如果該值必須從第二個子 json 獲取 "refDataId": 2,
查看完整描述

2 回答

?
UYOU

TA貢獻1878條經驗 獲得超4個贊

您可以使用我使用過的任何 json 解析器來提取數據org.json


以下代碼嘗試從您的 json 數據中查找 OFFICER。


JSONObject obj = new JSONObject(jsonString);


    JSONArray objArray = obj.optJSONArray("root");


    for (Object jo : objArray) {

        JSONObject arrayElement = new JSONObject(jo.toString());

        JSONArray childrenArray = arrayElement.getJSONArray("children");


        for (Object child : childrenArray) {


            JSONObject childJo = new JSONObject(child.toString());


            if (Integer.parseInt(childJo.get("refDataId").toString()) == 99) {

                if (childJo.get("otherValue").toString().equals("Officer")) {

                    System.out.println("Success Officer Found !");

                }

            }


        }


    }


查看完整回答
反對 回復 2021-06-30
?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

在這里查看使用 drools Fluent API 的嵌套 JSON 迭代,在我看來,創建與 JSON 結構相對應的數據對象就足夠了。


查看完整回答
反對 回復 2021-06-30
  • 2 回答
  • 0 關注
  • 241 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號