//向服务器获取根目录
public static String getRootList() throws Exception{
String json = "{\"type\":\"getRootList\"}";
output.write(json.getBytes());
output.flush();
byte[] b = new byte[1024];
int len = input.read(b);
json = new String(b,0,len);//字符串进行转化
Config.ROOT_LIST_JSON_STR = json;
return json;
}
try {
String json_str = Config.service.getRootList();
System.out.println(json_str);
JSONObject json = JSONObject.fromObject(json_str);//对json的解析
JSONArray jsonArray_mulu = json.getJSONArray("mulu");
JSONArray jsonArray_files = json.getJSONArray("files");
this.removeAll();
int count = jsonArray_mulu.size()+jsonArray_files.size();
for (int i = 0; i < jsonArray_mulu.size(); i++) {
JSONObject mulu = jsonArray_mulu.getJSONObject(i);
this.add(new FileJPanel(mulu.getString("rdid"), mulu.getString("did"), "DIR", mulu.getString("dname")));
}
for (int i = 0; i < jsonArray_files.size(); i++) {
JSONObject file = jsonArray_files.getJSONObject(i);
this.add(new FileJPanel(file.getString("did"), file.getString("fid"), "FILE", file.getString("fname")));
}
this.setPreferredSize(new Dimension(508,(count/5+(count%5==0?0:1))*135));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
javax.swing.JOptionPane.showMessageDialog(this.getParent(), "网络异常,请稍后再试");
}
相关的代码贴出来了,但不是很理解这个数组怎么就越界了。也不知道怎么去修改