I have a seemingly simple piece of JSON that I am attempting to parse (from Facebox running on Docker)
The following code is close to what I wish to achieve, but I am getting errors with the string builder:
From what I can make out, it appears that the stringBuilder object that I create ( val StringBuilder sb2 = new StringBuilder
)is not accesible from within the for loop?( for (i : 0 .. (maxCount -1)){
)
All that I am trying to do (for now) is extract matched face names from the json output.
Here is my current code:
val StringBuilder sb2 = new StringBuilder val faceCount = transform("JSONPATH", "$.facesCount", json.toString) val maxCount = Integer::parseInt(faceCount).intValue val Number matches = 0 logInfo("===JSON PARSER===", faceCount.toString + " faces discovered") for (i : 0 .. (maxCount -1)){ val faceConfidence = Float::parseFloat( transform("JSONPATH", "$.faces[" +i+"].confidence", json.toString)) as Number if(faceConfidence > 0.5){ logInfo("===JSON PARSER===", "Matching face " + i + " discovered") matches = matches + 1 val whosThere = (transform("JSONPATH", "$.faces[" +i+"].name", json.toString)).toString sb2.append(", " + whosThere ) } else { logInfo("===JSON PARSER===", "Strange face " + i + " discovered") } }
This is my json object
{
“success”: true,
“facesCount”: 3,
“faces”: [{
“rect”: {
“top”: 345,
“left”: 902,
“width”: 186,
“height”: 186
},
“matched”: false,
“confidence”: 0
}, {
“rect”: {
“top”: 231,
“left”: 230,
“width”: 268,
“height”: 267
},
“matched”: false,
“confidence”: 0
}, {
“rect”: {
“top”: 469,
“left”: 1109,
“width”: 185,
“height”: 186
},
“id”: “ouma2.JPG”,
“name”: “ouma”,
“matched”: true,
“confidence”: 0.5692880948411863
}]
}
and lastly, this is the error I get in my logs:
09-12 16:04:09.450 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test Rule': An error occurred during the script execution: Couldn't invoke 'assignValueTo' for feature JvmVoid: (eProxyURI: _test.rules#|::0.2.0.2.0.8.1.0.7::0::/1)
==> /log/events.log <==