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

          主站蜘蛛池模板: 柘荣县| 闸北区| 宁河县| 平原县| 昌都县| 南丹县| 隆林| 南通市| 保山市| 平顺县| 措美县| 新泰市| 余庆县| 舟曲县| 临猗县| 平度市| 太和县| 龙南县| 商城县| 永丰县| 榆社县| 府谷县| 镇雄县| 彭泽县| 新晃| 潼南县| 屯留县| 陆河县| 镇江市| 观塘区| 来凤县| 台中市| 佳木斯市| 洛浦县| 南平市| 衡阳市| 三门峡市| 玛曲县| 佛坪县| 贵阳市| 台江县|