簡體   English   中英

Json object inside array inside json object using kotlin or java

[英]Json object inside array inside json object using kotlin or java

I would like to put a json object inside an array, inside another json object using java or kotlin. 像這樣的東西:

{
  "strName" : "hello world"
  "arrAddress" : [
    {
      "strAddress" : "52 street",
      "strPincode" : "683543"
    }
  ]
}

我研究了其他問題,但找不到合適的答案。

如果有人想使用像這樣的 JSON 對象,我找到了答案:

JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("strName", "hello world");
        jsonObject.add("arrAddress", new JsonParser().parse(
                "[\n" +
                "    {\n" +
                "      \"strAddress\" : \"52 street\"\n," +
                "      \"strPincode\" : \"683543\"\n" +
                "    }\n" +
                "  ]"
        ));

Output:

{"strName":"hello world","arrAddress":[{"strAddress":"52 street","strPincode":"683543"}]}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM