variables - Counter in Java JsonPath expression -


i trying use counter in json path expression , getting jsonpath error java.lang.numberformatexception

    (int counter = 0; counter < ids.size(); counter++) {         tmp_rules = jsonpath.read(jsonfile, "$..orders[counter].rule");         (int counter2 = 0; counter2 < tmp_rules.size();counter2++){             if (                     (jsonpath.read(jsonfile, "$..orders[counter].rule[counter2]") == 1) &&                     (jsonpath.read(jsonfile, "$..orders[counter].asked[counter2]")) != 0) {                        end_id.add(jsonpath.read(jsonfile, "$..id[counter]"));                        end_rule.add(jsonpath.read(jsonfile, "$..orders[counter].rule[counter2]"));                        end_asked.add(jsonpath.read(jsonfile,"$..orders[counter].asked[counter2]"));             }         }     } 

your json path expressions not valid, since use counter , counter2 strings indexing arrays. should rather use values of loop variables in path expressions:

for (int counter = 0; counter < ids.size(); counter++) {     tmp_rules = jsonpath.read(jsonfile, "$..orders[" + counter + "].rule");     (int counter2 = 0; counter2 < tmp_rules.size();counter2++){         if (                 (jsonpath.read(jsonfile, "$..orders[" + counter + "].rule[" + counter2 + "]") == 1) &&                 (jsonpath.read(jsonfile, "$..orders[" + counter + "].asked[" + counter2 + "]")) != 0) {                    end_id.add(jsonpath.read(jsonfile, "$..id[" + counter + "]"));                    end_rule.add(jsonpath.read(jsonfile, "$..orders[" + counter + "].rule[" + counter2 + "]"));                    end_asked.add(jsonpath.read(jsonfile,"$..orders[" + counter + "].asked[" + counter2 + "]"));         }     } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -