我有一个JAVA for循环打印输出,如下所示。
inside for loop::{"state":"tess","path":"/content/projectpath/en/men"} inside for loop::{"state":"hello","path":"/content/projectpath/en/women"}
我的任何代码段如下所示。
for (Value val : values) {
//jsonobj = new JSONObject(val.getString());
out.println("inside for loop::" + val.getString());
// JSONArray jsonarr = val.getString();
}// out.println("::"+jsonobj.toString());
如何在for循环之后获取一个JSON数组,其值应为{"state":"tess","path":"/content/projectpath/en/men"}
和{"state":"hello","path":"/content/projectpath/en/women"}
答案 0 :(得分:3)
像这样创建一个JSONArray。在循环对象上插入循环对象。最后你会得到一个数组,请尝试一下。
JSONArray list = new JSONArray();
list.add(val);