JSONObject 이름/값 의 정렬되지 않은 컬렉션입니다. 문자열에서 텍스트를 쌍 및 구문 분석하여 지도 생성 -같은 물건. 그러나 자동 증가 increment() 를 사용하는 JSONObject의 속성 JSONObject 클래스의 메소드 해당 속성이 없으면 1 값으로 생성합니다. . 그러한 속성이 있고 그것이 Integer, Long, Double 또는 Float이면 하나를 추가하십시오.
구문
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
}