我必须做出一个JSON格式的文件,它必须看起来像以下:添加数组JSON文件,没有钥匙
xyz.json
[
{
"imagelist": "/oracle/public/oel6",
"label": "test_higgs",
"shape": "small",
"name" : "/Compute-computecli1/computeadmin/",
"networking" : {
"eth0" : {
"ipnetwork" : "/Compute-computecli1/computeadmin/ipnet"
}
}
}
]
数组应在JSON文件中添加没有{},这些花括号必须进入JSON数组中。
代码为
{
instances:[
{
"imagelist": "/oracle/public/oel6",
"label": "test_higgs",
"shape": "small",
"name" : "/Compute-computecli1/computeadmin/",
"networking" : {
"eth0" : {
"ipnetwork" : "/Compute-computecli1/computeadmin/ipnet"
}
}
}
]
}
是:
该代码添加JSON数组作为值“实例”键,但我想补充JSON数组没有JSON关键。
JsonObject ipnetwork = new JsonObject();
ipnetwork.addProperty("ipnetwork", ipNetworkName);
JsonObject interface_type = new JsonObject();
interface_type.add("eth0", ipnetwork);
JsonObject instance = new JsonObject();
instance.addProperty(imageListCmdText, "/oracle/public/oel6");
instance.addProperty("label","test_higgs");
instance.addProperty("shape","small");
instance.addProperty("name","/"+customerName);
instance.add("networking",interface_type);
JsonArray instances = new JsonArray();
instances.add(instance);
JsonObject launch_plan = new JsonObject();
launch_plan.add("instances", instances);
请告诉我们如何改变这段代码以获得上面提到的输出。
是吗?到目前为止,你尝试过什么?你的代码在哪里?你有什么问题? – UnholySheep
{ 实例:[ { “图像列表”: “/ ORACLE /公共/ oel6”, “标签”: “test_higgs”, “形状”: “小”, “名称”:“/计算-computecli1/computeadmin /”, “网络”:{ “eth0的”:{ “ipnetwork”: “/计算-computecli1/computeadmin/IPNET” } } } ] } –
我试图代码此!!但我没有得到如何获得问题中提到的上述代码 –