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 閱讀(263) 評(píng)論(0)  編輯  收藏 所屬分類: J2SEJSON

          主站蜘蛛池模板: 巍山| 铜梁县| 屏边| 怀仁县| 弥勒县| 武义县| 鄂托克旗| 石棉县| 阳曲县| 唐海县| 宝清县| 宜兴市| 巴彦淖尔市| 新民市| 曲阳县| 宁晋县| 吉隆县| 津市市| 云和县| 旅游| 梧州市| 大石桥市| 南郑县| 浦江县| 日喀则市| 增城市| 无极县| 高唐县| 喀什市| 南丰县| 都匀市| 沭阳县| 水城县| 大港区| 淮安市| 都昌县| 金山区| 北票市| 土默特右旗| 芜湖市| 勃利县|