语法
public JSONObject increment(java.lang.String key) throws JSONException
import org.json.JSONException; import org.json.JSONObject; public class IncrementJSONObjectTest { public static void main(String[] args) throws JSONException { JSONObject jsonObj = new JSONObject(); jsonObj.put("year", 2019); jsonObj.put("age", 25); System.out.println(jsonObj.toString(3)); jsonObj.increment("year").increment("age"); System.out.println(jsonObj.toString(3)); jsonObj.increment("year").increment("age"); System.out.println(jsonObj.toString(3)); jsonObj.increment("year").increment("age"); System.out.println(jsonObj.toString(3)); } }
{ "year": 2019, "age": 25 } { "year": 2020, "age": 26 } { "year": 2021, "age": 27 } { "year": 2022, "age": 28 }
以上就是如何在Java中自动增加JSONObject的属性?的详细内容,更多请关注php中文网其它相关文章!
已抢186823个
抢已抢67385个
抢已抢353355个
抢已抢667778个
抢已抢123000个
抢已抢24446个
抢