paulwong

          Pretty print JSON using org.json library in Java

          Syntax

          public java.lang.String toString(int indentFactor) throws JSONException

          Example

          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
             }
          }

          Output

          Pretty Print of JSON:
          {
             "Salary": 25000,
             "Age": 25,
             "Name": "Jai"
          }

          posted on 2020-10-28 17:17 paulwong 閱讀(266) 評論(0)  編輯  收藏 所屬分類: J2SEJSON

          主站蜘蛛池模板: 大兴区| 巴东县| 利川市| 喀什市| 东城区| 六枝特区| 察隅县| 大足县| 外汇| 治多县| 朔州市| 曲水县| 黎川县| 郓城县| 汉沽区| 呼和浩特市| 砀山县| 广饶县| 闽清县| 澄迈县| 甘泉县| 平果县| 海口市| 方城县| 新巴尔虎右旗| 济宁市| 宜州市| 蒲江县| 凌海市| 会宁县| 蒙山县| 长乐市| 新宾| 莱州市| 石阡县| 东海县| 来宾市| 黄龙县| 关岭| 蕉岭县| 涞源县|