import net.minidev.json.parser.JSONParser;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONArray;
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
String response = prev.getResponseDataAsString();
JSONObject jsonresponse = (JSONObject) p.parse(response);
JSONObject json2 = (JSONObject) jsonresponse.get("Key1");
JSONObject newjson = new JSONObject();
newjson.put("displayValue", json2.get("displayValue"));
newjson.put("value", json2.get("value"));
jsonresponse.put("Key2", newjson);
if(jsonresponse.has("Key3"))
{
jsonresponse.remove("Key3");
jsonresponse.put("Key3", jsonresponse.get("Key3").get("value");
}
log.info(jsonresponse.toString());
I need to enter the if loop to remove the json key value if it exists and replace it with something else.
import net.minidev.json.parser.JSONParser; import net.minidev.json.JSONObject; i . . . '' : Typed variable declaration : Undefined argument: Key3 : at Line: 17 : in file: inline evaluation of:import net.minidev.json.parser.JSONParser; import net.minidev.json.JSONObject; i . . . '' : ( Key3 ) in inline evaluation of: ``import net.minidev.json.parser.JSONParser; import net.minidev.json.JSONObject; i . . . '' at line number 17 - Om Prakash Yadav