ソースを参照

:sparkles: Ajout bibilotheque JSON Java avec exemple

Arthur Brandao 6 年 前
コミット
26fbec5e07
3 ファイル変更72 行追加0 行削除
  1. BIN
      Client/json.jar
  2. 39 0
      Client/jsontest/JsonTest.java
  3. 33 0
      Client/jsontest/Test.java

BIN
Client/json.jar


+ 39 - 0
Client/jsontest/JsonTest.java

@@ -0,0 +1,39 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package jsontest;
+
+import java.util.ArrayList;
+import org.json.*;
+
+/**
+ *
+ * @author Loquicom <contact@loquicom.fr>
+ */
+public class JsonTest {
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        JSONObject jo = new JSONObject();
+        Test t = new Test();
+        ArrayList<Boolean> tab = new ArrayList<>();
+        tab.add(true);
+        tab.add(false);
+        tab.add(true);
+        tab.add(true);
+        
+        jo.put("bool", true);
+        jo.put("tab", tab);
+        jo.put("obj", t.toJson());
+        jo.put("int", 89);
+        jo.put("nb", 42.6);
+        
+        System.out.println(jo.toString(1));
+    }
+    
+    
+}

+ 33 - 0
Client/jsontest/Test.java

@@ -0,0 +1,33 @@
+package jsontest;
+
+import org.json.JSONObject;
+
+public class Test{
+        
+        private int aze;
+        private String rty;
+        
+        public Test(){
+            this.aze = 8;
+            this.rty = "Bjr";
+        }
+
+        public int getAze() {
+            return aze;
+        }
+
+        public String getRty() {
+            return rty;
+        }
+        
+        public String toString(){
+            JSONObject jo = new JSONObject(this);
+            return jo.toString();
+        }
+        
+        public JSONObject toJson(){
+            return new JSONObject(this);
+        }
+        
+    }
+