如何使用 JSONObject Java 创建如下所示的 JSON 对象和数组?
{ "inputs": [ { "addresses": [ "tb1qhtsz7fng0ghlln335ykt3hzsyunaugcaz4z0l2" ] } ], "outputs": [ { "addresses": [ "tb1qsehy2rp6eehuuu9lvluh9j9qa4xyfq38s0twlj" ], "value": 10000 } ] }
问问题
20 次
1 回答
0
JsonArray addressJsonArray = new JsonArray();
addressJsonArray.add("tb1qsehy2rp6eehuuu9lvluh9j9qa4xyfq38s0twlj");
JsonObject objOutputs = new JsonObject();
objOutputs.addProperty("value", 1000);
objOutputs.add("addresses", addressJsonArray);
JsonArray jsonArrayOutputs = new JsonArray();
jsonArrayOutputs.add(objOutputs);
JsonArray addressJsonArrayInput= new JsonArray();
addressJsonArrayInput.add("tb1qhtsz7fng0ghlln335ykt3hzsyunaugcaz4z0l2");
JsonObject objInputs = new JsonObject();
objInputs.add("addresses", addressJsonArrayInput);
JsonArray jsonArrayInputs = new JsonArray();
jsonArrayInputs.add(objInputs);
JsonObject obj = new JsonObject();
obj.add("inputs", jsonArrayInputs);
obj.add("outputs", jsonArrayOutputs);
于 2022-02-17T04:34:02.010 回答