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) 評論(0)  編輯  收藏 所屬分類: J2SEJSON

          主站蜘蛛池模板: 方山县| 六安市| 张家界市| 句容市| 隆安县| 平山县| 九龙坡区| 壶关县| 内乡县| 景谷| 南平市| 深圳市| 龙州县| 仁寿县| 綦江县| 衡东县| 海南省| 陆丰市| 南阳市| 扎鲁特旗| 武川县| 隆昌县| 汉源县| 孙吴县| 邯郸市| 元阳县| 宁德市| 鹤庆县| 衡阳县| 离岛区| 沭阳县| 渝中区| 东乡县| 习水县| 保定市| 南平市| 沙洋县| 华蓥市| 天峨县| 岳普湖县| 乐安县|