JSON 가벼운 텍스트 기반 및 언어 독립적 그 데이터 교환 형식. A.JSON객체 문자열에서 텍스트를 구문 분석하여 지도를 생성할 수 있습니다. -같은 물건. 개체는 콘텐츠를 조작하고 JSON 호환 개체 직렬화를 생성하기 위한 메서드를 제공합니다. org.json의 파일 패키지 구현 JSON 인코더/디코더 자바에서. 또한 JSON, XML, HTTP 헤더, 쿠키 및 CDL.
우리는 예쁘게 인쇄할 수 있습니다. toString(int indentFactor을 사용하는 JSON ) org.json. 메소드 JSON객체 클래스, 여기서 indentFactor 각 들여쓰기 수준에 추가할 공백 수입니다.
구문
public java.lang.String toString(int indentFactor) throws JSONException
예시
import org.json.*;
public class JSONPrettyPrintTest {
public static void main(String args[]) throws JSONException {
String json = "{" +
"Name : Jai," +
"Age : 25, " +
"Salary: 25000.00 " +
"}";
JSONObject jsonObj = new JSONObject(json);
System.out.println("Pretty Print of JSON:");
System.out.println(jsonObj.toString(4)); // pretty print json
}
} 출력
Pretty Print of JSON:
{
"Salary": 25000,
"Age": 25,
"Name": "Jai"
}