javajsongetstring

Unable to get the required value from JSON in java" The method getString(String) is undefined for the type String""


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,


Solution

  • 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);
        }
    }