如何每次切换 boolean 值,然后将其分配给 json 中的“test
”键?
JSONObject json=new JSONObject();
json.put("test",true);
return json.toString();
最佳答案
您必须获取当前值,翻转它,然后将其设置回来。
String jsonText = "{\"test\":true}"; // or wherever you have your json
JSONObject json = new JSONObject(jsonText);
if (json.has("test")) {
json.put("test", !json.getBoolean("test"));
} else {
json.put("test", true);
}
关于java - 在 json java 中切换值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29543397/