有人可以提供我的Java代碼來創建一個JSON對象如下圖所示在Java中創建一個JSON數據對象
{"main":[
["one","two","three","four","five"],
["one","two","three","four","five"],
["one","two","three","four","five"],
["one","two","three","four","five"],
["one","two","three","four","five"]
]}
我已經試過類似
Gson gson = new Gson();
JsonArray array = new JsonArray();
array.add(new JsonPrimitive("One"));
array.add(new JsonPrimitive("two"));
array.add(new JsonPrimitive("three"));
array.add(new JsonPrimitive("four"));
array.add(new JsonPrimitive("five"));
JsonObject jsonObject = new JsonObject();
jsonObject.add("main", array);
我越來越像下面的結果甚至當我在循環
{"main":["one","two","three","four","five"]}
像一個單一的對象。但我期待的結果像
{"main":[
["one","two","three","four","five"],
["one","two","three","four","five"],
["one","two","three","four","five"],
["one","two","three","four","five"],
["one","two","three","four","five"]
]}
非常感謝提前。