MAP数组

来源:互联网 发布:高仿鞋淘宝 编辑:程序博客网 时间:2024/06/05 16:03
Map[] maps=new Map[len];
JSONArray jsonArray=new JSONArray();
for(int i=0;i<len;i++){
maps[i]= new HashMap();
JSONObject jsonObject=new JSONObject();
if(taskIds[i]!=null || taskIds[i]!=""){
maps[i].put("userId", userId);
maps[i].put("Task_ID", taskIds[i]);
int node_id=Integer.parseInt(NodeIds[i]);
maps[i].put("Node_ID", node_id);
maps[i].put("taskName", taskNames[i]);
maps[i].put("operationID", operationID);
maps[i].put("refreshUrl", refreshUrl);
   maps[i].put("openTabId", openTabIds[i]);
   maps[i].put("opinion", opinion);
   jsonObject.put("taskId",  taskIds[i]);
   jsonObject.put("nodeId",  node_id);
   jsonArray.put(i,jsonObject);
}

}

在以上代码中需要使用MAP数组,而改数组的每一项也是一个map。之前的操作是在for循环中每次定义一个map,然后将他put到MAP数组中,后来证实这种做法不可取。最后该改进为上面的写法,之前想MAP[i]中去put所需要的数据。

原创粉丝点击