Toggle doesn't work - java -


i trying toggle value of key1 in same value time. doing wrong here?

boolean jsontext =  true; jsonobject jsonobj = new jsonobject();  public void setjsonobject(boolean val){     this.jsontext = val; }  public boolean getjsonobject(){     return this.jsontext; }  @post("/hello")     @permitall     public string hello(string text) {      try {            if (jsonobj.has("key1")) {             boolean val = !jsonobj.getboolean("key1");             jsonobj.remove("key1");             jsonobj.put("key1", val);         } else {             jsonobj.put("key1", true);         }     } catch (jsonexception e) {         e.printstacktrace();     }      return "some result";      } 

am resetting "key1" boolean value somewhere?

you creating new json object every time:

jsonobject jsonobj = new jsonobject(); 

so never has value "key1" , set true after hello code.


Popular posts from this blog