java后台循环遍历JSONArray

不凡 后台 1.1K+

JSONArray数据

[{
	"allname": "根节点",
	"parent": "#",
	"code": "",
	"licensePlateNumber": "",
	"id": "0",
	"text": "根节点",
	"dept": "0",
	"useCarMoney": "1"
}, {
	"allname": "工会经费",
	"parent": "0",
	"code": "0",
	"licensePlateNumber": "",
	"id": "0528bd30-275f-4081-913b-2cfbd8c23809",
	"text": "工会经费(全部)",
	"dept": "全部",
	"useCarMoney": "1"
},  {
	"allname": "政府采购",
	"parent": "0",
	"code": "3",
	"licensePlateNumber": "冀D9999",
	"id": "47ef40ef-9533-4a51-bc19-3e7d4c52a3a2",
	"text": "政府采购(YXWHC)",
	"dept": "YXWHC",
	"useCarMoney": "0"
}]

java 后台方法

JSONArray arr = treeService.findAllIndexToJson();
Iterator<Object> it = arr.iterator();
while (it.hasNext()) {
    JSONObject ob = (JSONObject) it.next();
    if(ob.getString("text")!=null){
        String text=ob.getString("text");
           //此处可根据getString()/getDate()等方法拿到每个josn对象的值
    }
}


标签: java

发布评论 0条评论)

  • Refresh code

还木有评论哦,快来抢沙发吧~