-1

I have 2 json's where I need to compare and get the matching value, I am using the below way in java where the boolean condition works fine and returns true after the comparison but unable to get the value from getString, Receiving the error message "

the boolean condition works fine and returns the value as true

So i converted the to a JsonObject and resolved the original issue stated in this issue by following the below step,

SimbuStar
  • 623
  • 1
  • 7
  • 18
  • 1
    `scriptToRunJsonString` looks like an instance of a String. A String has no method called `getString` - and what would that even do, anyway? – Michael Jun 07 '18 at 07:56
  • Why do you iterate on `JsonargumentdetailsforRunner` while you use `scriptToRunJsonString` inside the loop? You are running an out-of-index exception risk here (plus, it doesn't make sens). – Ahmad Shahwan Jun 07 '18 at 08:07
  • @AhmadShahwan -Yes agree, i did get an out-of-index exception here after i resolved the issue stated in this question. How to resolve the out-of-index exception in this case ? – SimbuStar Jun 07 '18 at 13:24
  • @SimbuStar you can check [my answer](https://stackoverflow.com/a/50736046/3402449) for that. – Ahmad Shahwan Jun 07 '18 at 14:42
  • @AhmadShahwan - Great. Thanks..Its working as expected – SimbuStar Jun 07 '18 at 15:18

1 Answers1

-1

scriptToRunJsonString is a string, use JsonargumentdetailsforRunner which is a collection instread.

Unfortunately, you didn't mention the types of your objects, trying this may work depending on the real type of JsonargumentdetailsforRunner.

for (int i = 0; i < argumentdetailsforRunner.length(); i++) {
    String key = argumentdetailsforRunner.get(i).getScriptArgumentName().toString();
    if (JsonargumentdetailsforRunner.contains(key)) {
        String argumentStringValue=JsonargumentdetailsforRunner.getString(key);
        log.info(argumentStringValue);
    }
}
Ahmad Shahwan
  • 1,662
  • 18
  • 29